【发布时间】:2018-02-22 02:07:22
【问题描述】:
我正在获取产品列表,然后使用 FlatList 显示,我的列表包含 5 个项目,您可以看到 FlatList 行高是可变的,因为描述文本不同。所以问题是我的最后一个项目卡不完全可见,也许这是某种平面列表问题或布局问题。任何帮助将不胜感激
renderProducts() {
if (this.props.loading === true) {
return (
<View style={Styles.spinnerStyle}>
<ActivityIndicator size='large' />
</View>
);
}
return (
<FlatList
data={this.props.myProducts}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<Card
title={item.title}
image={{
uri: item.image !== null ? item.image.src :'../resImage.jpg'
}}
>
<Text style={{ marginBottom: 10 }}>
{item.body_html}
</Text>
<Button
icon={{ name: 'code' }}
backgroundColor='#03A9F4'
fontFamily='Lato'
buttonStyle={{ borderRadius: 0, marginLeft: 0, marginRight: 0, marginBottom: 0 }}
title='VIEW NOW'
/>
</Card>
)}
/>
);
}
render() {
return (
<View>
<View style={Styles.viewStyle}>
<Text style {Styles.textStyle}>ProductsList</Text>
</View>
{
this.renderProducts()
}
</View>
);
}
【问题讨论】:
-
"...如你所见"实际上我们不能,因为你没有发布任何代码。
-
现在看看。
-
尝试在
FlatList组件的底部添加填充。<FlatList style={{ paddingBottom: 20 }} ... /> -
嘿,这是解决问题的唯一方法吗?添加一个 marginBottom 也对我有用,但这似乎有点 hack,不是吗?
-
谢谢。它解决了我的问题:)
标签: react-native react-native-flatlist