listview部分内容的容器响应本机

时间:2017-04-12 04:43:21

标签: react-native react-native-android react-native-listview

我有一个包含章节标题的列表视图,我不想在容器中包含部分内容(每个部分内容)并为其添加边框。这怎么可能 ?

1 个答案:

答案 0 :(得分:0)

我编写了一个示例代码,其中包含listView中不同行的边框/分隔符。 renderSeparator是你应该寻找的功能。希望它有所帮助。

const styles = StyleSheet.create({
  separator: {
    flex: 1,
    height: StyleSheet.hairlineWidth,
    backgroundColor: '#8E8E8E',
  },
});

class ListViewDemo extends Component {

  render() {
    return (
     <ListView
      style={styles.container}
      dataSource={this.state.dataSource}
      renderRow={(data) => <View><Text>{data}</Text></View>}
      renderSeparator={(sectionId, rowId) => <View key={rowId} style=
      {styles.separator} />} // See this line. renderSeperator is responsible for providing the border.
     />
    );
  }
}