android - react native : Blank space between FlatList rendered items

标签 android react-native react-native-flatlist

我正在尝试使用 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>

this is what i see in screen

它是样式:

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',

},

我设置了上下文本的背景颜色来查找问题,但我对此一无所知。

你能指导我解决这个问题吗?ಠ_ಠ

最佳答案

我给你举了个例子。看这个。你我之间没有差距。

我的 parent 是扁平主义者

您不必像这样将 View 放在一边。您可以将 View 放在您想要的项目中。

import React, { Component } from 'react';
import { View, Text, FlatList } from 'react-native';

const users = [
  {
    name: 'Cathy Gilliam',
    company: 'EXOVENT',
    email: 'cathygilliam@exovent.com',
  },
  {
    name: 'Norton Potts',
    company: 'COREPAN',
    email: 'nortonpotts@corepan.com',
  },
  {
    name: 'Kelly Collins',
    company: 'SECURIA',
    email: 'kellycollins@securia.com',
  },
];

export default class App extends Component {
  render() {
    return (
      <FlatList
        data={users}
        renderItem={({ item }) => (
          <View
            style={{
              borderBottomWidth: 1,
              borderBottomColor: 'grey',
              padding: 10
            }}>
            <View>
              <Text style={{ fontWeight: 'bold', fontSize: 18 }}>{item.name}</Text>
              <Text>{item.company}</Text>
              <Text>{item.email}</Text>
            </View>
          </View>
        )}
      />
    );
  }
}

关于android - react native : Blank space between FlatList rendered items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57676132/

相关文章:

android - KOTLIN 在键盘显示时调整 fragment ScrollView

android - googleMap.getMyLocation();无法获取当前位置

android - 自定义微调器对齐和宽度的问题

java - 如何从 java 类更改自定义键盘按键的背景?

react-native - 在 UIManager 中找不到 RNTMap

react-native - react native : Correct scrolling in horizontal FlatList with Item Separator

javascript - 当电缆与我的智能手机断开连接时,它会运行我的 React Native 应用程序的旧代码

android - React Native fetch() 在 Android 7 上抛出 'Network request failed',但在 Android 6 上工作正常

react-native - 水平 FlatList 前后的间距(React Native)

javascript - 当我们到达列表底部时,React Native FlatList 加载更多