加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native ListView的属性flexWrap为wrap失效解决

发布时间:2020-12-15 07:32:07 所属栏目:百科 来源:网络整理
导读:最近在参照某些例子学习React-native 开发iOS和Android的app时,碰到如标题所示的问题: ListView的属性flexWrap为wrap不起作用。 如下可以看到每一行的其实是有10个图标的,自动换行之后,第一页的下满三个不见了: 代码如下: 大家可以看: flexDirection:

最近在参照某些例子学习React-native 开发iOS和Android的app时,碰到如标题所示的问题:
ListView的属性flexWrap为wrap不起作用。
如下可以看到每一行的其实是有10个图标的,自动换行之后,第一页的下满三个不见了:

代码如下:
大家可以看:
flexDirection:'row',
flexWrap:'wrap',

采取了,横向,自动换行,效果是达到了了,可是,下面的换行后的图标确是不见了!!

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
import React,{ Component } from 'react'; import { AppRegistry,StyleSheet,Text,View,Image,ListView } from 'react-native'; import Dimensions from 'Dimensions'; var {width,height} = Dimensions.get('window'); export default class TopListView extends Component{ static defaultProps ={ dataArr : [] } constructor(props){ super(props); var ds = new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2}); this.state={ dataSource:ds.cloneWithRows(this.props.dataArr),} } render() { return ( <ListView dataSource = {this.state.dataSource} renderRow={this.renderRow.bind(this)} contentContainerStyle={styles.contentViewStyle} scrollEnabled={false} /> ) } renderRow(rowData){ return ( <View style={styles.cellStyle}> <Image source={{uri:rowData.image}} style={{width:52,height:52}}/> <Text>{rowData.title}</Text> </View> ); } } const styles = StyleSheet.create({ contentViewStyle:{ flexDirection:'row',flexWrap:'wrap',// 屏幕宽度 width:width,},cellStyle:{ } });

踩坑之后的解决方法:
解释原因:由于在rn 0.28之后的版本上官方已经修改了flexWrap:'wrap'的工作方式了,之前版本的是flexWrap:'wrap'和默认的alignItems: 'stretch'是一起工作的;如果是0.28之后的版本,你需要加上alignItems: 'flex-start'
如下:

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
contentViewStyle:{ flexDirection:'row',alignItems:'flex-start',// 屏幕宽度 width:width,},

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读