React Native ListView占据100%的高度

时间:2017-09-28 06:25:15

标签: react-native-ios

enter image description here

即使列表中的内容较少,我的ListView容器也会占据100%的高度。

我的代码:

<View style={{ flex: 1, width: '95%', flexDirection: 'row', justifyContent: 'center', alignSelf: 'center' }}>
  <Card style={{ width: '95%', alignSelf: 'center', marginTop: 10 }}>
   <ListView
     dataSource={this.state.dataSource}
     renderRow={(item) =>
           <CardItem
              key={`transaction-${item.data.transactionid}`}
           >
                 // my list code was here
           </CardItem>}
     ListFooterComponent={this.renderFooter}
     onRefresh={this._onRefresh}
     refreshing={this.state.refreshing}
     onEndReached={this.fetchGoalTransactions}
     onEndReachedThreshold={50}
    />
 </Card>

1 个答案:

答案 0 :(得分:0)

<View style={{flex:1}}>
 <View style={{flex:2}}>
    //Here is your List View
</View>
<View style={{flex:2}}>
//Its a Empty View
</View>
</View>

为了绑定ListView的高度,可以直接设置视图的高度(不鼓励),也可以确保所有父视图都具有有界高度,因为Lisview使用Scrollview

来自ScrollView docs