简体   繁体   English

react-native FlatList显示-顶部空白

[英]react-native FlatList displaying - the blank on the top

when i initialize the page, it was showing like these.(photo is bellow) 当我初始化页面时,它像这样显示。(照片在下面)
it's alway has the blank space(orange one) on the screen,which was include in the FlatList . 屏幕上总是有空白(橙色),它包含在FlatList中
(I used the '< Text > 1 ' to showing there is no blank between text and flatlist.) (我使用'<Text> 1'来显示文本和平面列表之间没有空白。)
first photo 第一张照片

And,when i scroll down the page, it will like this.(photo is bellow) 而且,当我向下滚动页面时,它会像这样。(照片在下面)
it can over display the orange place, and look at the scroll bar on the right. 它可以过度显示橙色位置,并查看右侧的滚动条。 it's not on the top. 它不在顶部。 So i think it has the blank on the top of the flatlist area. 所以我认为它在平板列表区域的顶部具有空白。
I had Google it for two days, but no one has same issue like me... 我用Google进行了两天,但没有人遇到像我这样的问题...
Did anyone know what the blank is that and how to disable that blank? 有谁知道那是什么空白以及如何禁用该空白?
because i want the it like the seconed photo, when the first element showing up. 因为当第一个元素出现时,我希望它像第二张照片一样。
seconed photo 第二张照片

My react naitve: 我的反应天真:
react-native-cli: 2.0.1 react-native-cli:2.0.1
react-native: 0.57.5 反应本机:0.57.5

var Arr = [{name:'河北省',},
           {name:'山西省',},
           {name:'辽宁省',},
           {name:'吉林省',},
           {name:'黑龙江省',},
           {name:'江苏省',},
           {name:'浙江省',},
           {name:'福州省',}];

class Featured extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            peo: [
                { key: 'Devin' },
                { key: 'Jackson' },
                { key: 'James' },
                { key: 'Joel' },
                { key: 'John' },
                { key: 'Jillian' },
                { key: 'Jimmy' },
                { key: 'Julie' }
            ]
        };

    }
    Cellheader(data){
    alert(data.name);
  }
  //列表的每一行
  renderItemView({item,index}){
    return(
      <TouchableOpacity style={{flex:1,
                                height:60,
                                backgroundColor:'orange',
                        }}
                        onPress={()=>{this.Cellheader(item)}}
                       >
        <View style={{backgroundColor:'green',
                      height:59,justifyContent: 'center',
                      alignItems: 'center'}}>
           <Text>{item.name}</Text>
        </View>
      </TouchableOpacity>
    );
  }
  //定义页头
  ListHeaderComponent(){
    return(
       <View style={{height:100,backgroundColor:'red',justifyContent: 'center',}}>
         <Text>ListFooterComponent</Text>
       </View>
    );
  }
  //定义页脚
  ListFooterComponent(){
    return(
       <View style={{height:40,backgroundColor:'yellow',justifyContent: 'center',}}>
          <Text>ListHeaderComponent</Text>
       </View>
    );
  }
    render() {
        for (var i = 0; i < Arr.length; i++) {
       Arr[i]['key'] = i;
        }
        return (
            <View style={styles.top}>
            <View
                    style={{
                        height: 100,
                        backgroundColor: 'skyblue',
                        alignItems: 'flex-end',
                        justifyContent: 'flex-end'
                    }}
                >
                    <TouchableOpacity style={styles.lnsertButton} underlayColor="#fff" onPress={this.onAddArray}>
                        <Text style={styles.submitText}>Insert</Text>
                    </TouchableOpacity>
                </View>
                <Text>1</Text>
                <FlatList style={{backgroundColor:'orange',flex:1}}
                  data = {Arr}
                  ListHeaderComponent={this.ListHeaderComponent.bind(this)}
                  ListFooterComponent={this.ListFooterComponent.bind(this)}
                  renderItem={this.renderItemView.bind(this)}
                  >

        </FlatList>
            </View>
        );
    }
}
var styles = StyleSheet.create({
    top: {
        flex: 1
    }
}

Sorry, My English isn't very good, please don't mind. 抱歉,我的英语不太好,请不要介意。

从renderItemView => TouchableOpacity删除flex:1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM