Muh*_*sin 6 flexbox reactjs react-native react-native-flexbox react-native-flatlist
每行中的项目将根据其文本大小而有所不同。Flatlist用于渲染项目。
标签视图.js
<View style={styles.tagView}>
<FlatList
scrollEventThrottle={1900}
data={this.state.interests}
numColumns={5}
renderItem={({ item }) => (
<View style={styles.tag}>
<Text>{item.tagName}</Text>
</View>
)}
keyExtractor={(item, index) => index}
contentContainerStyle={{ paddingBottom: 100 }}
/>
</View>
Run Code Online (Sandbox Code Playgroud)
风格
tagView: {
flex: 1,
flexDirection: "row",
flexWrap: "wrap"
},
tag: {
borderWidth: 1,
borderRadius: 10,
borderColor: "black",
backgroundColor: "white",
padding: 3,
marginTop: 5
}
Run Code Online (Sandbox Code Playgroud)
结果
但是这里的项目没有用设备宽度包装。有没有包装内容?
带有 columnWrapperStyle 的 FlatList
<FlatList
columnWrapperStyle={styles.tagView}
scrollEventThrottle={1900}
data={this.state.interests}
numColumns={5}
renderItem={({ item }) => (
<View style={styles.tag}>
<Text>{item.tagName}</Text>
</View>
)}
keyExtractor={(item, index) => index}
contentContainerStyle={{ paddingBottom: 100 }}
/>
Run Code Online (Sandbox Code Playgroud)
风格
tagView: {
flexWrap: "wrap"
},
Run Code Online (Sandbox Code Playgroud)
添加水平支柱并尝试,
<FlatList
scrollEventThrottle={1900}
data={this.state.interests}
numColumns={5}
horizontal={false}
renderItem={({ item }) => (
<View style={styles.tag}>
<Text>{item.tagName}</Text>
</View>
)}
keyExtractor={(item, index) => index}
contentContainerStyle={{ paddingBottom: 100 }}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6309 次 |
| 最近记录: |