【发布时间】:2019-08-27 13:48:59
【问题描述】:
我正在尝试使用 FlatList 在应用程序中显示一些获取的数据。它可以工作,但项目之间有一个非常大的空间!
这是我的 FlatList 代码:
<View style={styles.showresp}>
<FlatList
data={this.state.responsjson}
renderItem={({ item }) =>
<View style={styles.weatherview}>
<Text style={styles.city}>{item.name}</Text>
<Text style={styles.country}>{item.country}</Text>
<Text style={styles.temp}>{item.temp_c}</Text>
</View>}/>
</View>
它是样式:
showresp: {
backgroundColor: '#fffa',
height: 315,
marginRight: '10%',
marginLeft: '10%',
marginTop: '15%',
borderRadius: 15
},
weatherview:{
alignItems: 'center',
justifyContent: 'center',
flex :1
},
city: {
fontFamily :'Wonderbar Demo',
fontSize:40,
color:'#880e4f',
},
country:{
fontSize:20,
fontFamily:'Samim-Bold',
backgroundColor:'red',
},
temp:{
fontFamily :'Wonderbar Demo',
fontSize : 40,
backgroundColor:'green',
},
我设置了上下文本的背景颜色以找到问题,但我对此一无所知。
你能在这件事上指导我吗?ಠ_ಠ
【问题讨论】:
-
您是否在 style={styles.weatherview} 中添加了“flex:1”。请删除然后检查
-
是的,我试过了,但没用:/
-
你能展示你的样式文件吗?
-
我将它们添加到问题中
-
我试过你的代码,没有显示空间,“styles.showresp”的样式是什么。请补充问题
标签: android react-native react-native-android react-native-flatlist