android - 样式在 React Native 中无法正常工作

标签 android react-native styling

我正在学习使用 React Native 开发 Android 应用程序的教程 但是有一些奇怪的样式问题

  1. 不显示边框
  2. 第一行没有顶部填充
  3. 侧滚动条居中

Rendered display

这是我的代码:

import React, { Component } from 'react';
import {
  AppRegistry,
  ListView,
  StyleSheet,
  Text,
  View
} from 'react-native';

class SimpleList extends Component {
    constructor(props) {
        super(props);

        var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        this.state = {
            dataSource: ds.cloneWithRows(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
        };
    }

    _renderRow(rowData) {
        return <Text style={styles.row}>{rowData}</Text>
    }

    render() {
        return (<View style={styles.container}>
            <ListView
                dataSource={this.state.dataSource}
                renderRow={(e) => this._renderRow(e)}/>
        </View>);
    }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  row: {
    flex: 1,
    fontSize: 24,
    padding: 42,
    borderWidth: 1,
    borderColor: '#DDDDDD'
  }
});

export default SimpleList;

我的react native版本是0.30

最佳答案

我想我已经明白了

  • Top Padding 和 Border 不适用于 Text 组件,当我用 View 组件包装 Text 并改用包装器样式时它起作用
  • 通过使用 contentContainerStyle 而不是 style 属性来定义样式来修复滚动条

虽然不知道为什么它在教程中有效

关于android - 样式在 React Native 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38533236/

相关文章:

android - Pre-Lollipop 设备上 ImageButton 的提升效果

Android parcelable 和 Intent : redBundle: bad magic number

java - React Native : java. util.zip.ZipException : duplicate entry: com/google/android/gms/iid/zzc. 类

android - 防止 ImageView 在父布局范围之外绘制

java - Android 4.4 KitKat 无法快速关闭 ChunkedInputStream

react-native - 如何通过 React-native 中的 fabric.io 接收包含 JavaScript 方法、文件路径和行号的完整堆栈跟踪,而不是原生错误

react-native - 博览会应用程序-无法使用消息: This is taking much longer than it should加载项目

css - Xamarin.Forms - 像 CSS 一样的嵌套样式继承?

c# - 关于响应式设计的一些建议

html - 使用 CSS 自定义 HTML <select>