nin*_*yen 5 react-native react-native-flatlist
目前,我在使用 FlatList 时遇到了问题。我有一个组件来呈现列表簿。按照设计,header 的宽度是屏幕的宽度,body 将左右填充 10px。
所以我使用了contentContainerStyle={{paddingHorizontal: 10}}. 但是结果是header和body都是10px左右填充。
请提出解决方法。对不起,我的英语不好!!
更新:我很抱歉没有彻底描述我的问题。
在 main.tsx
...
public render() {
return (
<FlatList
key...
data={..}
renderItem={this.renderItems}
ListHeaderComponent={this.renderHeader}
contentContainerStyle={styles.contentStyle}
/>
);
}
private renderHeader = () => {
return (
<View style={style.header}
//TODO something ...
</View>
);
}
private renderItems: ListRenderItem<IBook> = ({ item: {bookId} }) => bookId ?
(
<BookGridCell
title={...}
image={...}
//TODO more..
/>
) : <View style={styles.emptyBox} />
}
Run Code Online (Sandbox Code Playgroud)
在renderItems,我调用了一个组件BookGridCell。在这个组件中,设置了书籍的设计。所以如果我直接在里面添加样式renderItems,每本书的左右边距都是10px,而不是整个正文。
contentContainerStyle
与 contenContainerStyle 一起使用时
直接在里面添加样式renderItems
时不要使用 contentContainerStyle
Chi*_*rma -2
为您的身体赋予风格。
style={styles.bodyContainer}
Run Code Online (Sandbox Code Playgroud)然后在样式表中添加属性。
const styles = StyleSheet.create({
bodyContainer: {
paddingHorizontal: 10
},
Run Code Online (Sandbox Code Playgroud)
这是正确的方法或者
您可以直接在视图中添加填充。
style={{ paddingHorizontal: 10 }}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
1774 次 |
| 最近记录: |