css - 如何使用 react-native-flatlist 在网格布局中对齐图像及其文本(超过一行的字符)
问题描述
如何在网格中对齐图像下方的文本。我已经使用 react-native-flatlist 显示了网格。但是图像下方长度较小的文本居中对齐并且可以正常工作。但是如果长度太长,它会显示在整个网格中,并且会隐藏网格右侧的下一个图像。如何在一行中显示长度是否太长。
我使用了下面的片段,我需要将图像下方的文本显示为与流行的看法相反,Lorem..
renderGridView(){
return (
<View style={{flex:1}}>
<FlatList
ref={(ref) => { this.flatListRef = ref; }}
data={data}
renderItem={({ item }) => this.renderGrid(item)}
numColumns={2}
extraData={data}
keyExtractor={item => item.id}
onEndReached={this._handleMore}
onEndReachedThreshold={0.001}
ListFooterComponent={this._renderFooter}
/>
</View>
)
}
renderGrid(item) {
return(
<TouchableOpacity activeOpacity = { .5 } >
<View style={{backgroundColor: 'white', alignItems: 'center'}}>
<Image style={{width: gridWidth, height: gridHeight}}
resizeMode={'contain'}
source={item.uri}/>
<Text numberOfLines={1}style={{fontSize: 12,textAlign: 'center'}} ellipsizeMode="tail">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words</Text>
<Text numberOfLines={1}style={{fontSize: 12,textAlign: 'center'}} ellipsizeMode="tail">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words</Text>
</View>
</TouchableOpacity>
);
}
在这里,如果像上面那样添加大量字符描述,它会显示在中心,而右侧的图像会隐藏在右侧。
有什么解决办法吗?
解决方案
在您的地图或网格的任何循环中尝试此操作:-
<View style={{alignItems: 'center'}}>
<Image source={require('your path')} />
<Text numberOfLines={1}style={{fontSize: 12}}
ellipsizeMode="tail">Contrary to popular belief, Lorem Ipsum is not simply
random text. It has roots in a piece of classical Latin literature from 45
BC, making it over 2000 years old. Richard McClintock, a Latin professor at
Hampden-Sydney College in Virginia, looked up one of the more obscure Latin
words</Text>
</View>
推荐阅读
- r - R - 通过字符调用 xts
- c# - Xamarin 表单上的 Mobile Offline Sync 数据库
- python - Python Intellisense VSCode 错误的自动完成导入和 PyLint 错误的导入错误警告
- java - 性能升级
- python - 导入多个csv时如何有条件地添加一列
- scala - 使用嵌套列将 csv 读入 Dataframe
- arrays - 为什么我的推送方法在使用 Ionic 时不起作用?
- aws-amplify - AWS Amplify TypeError:与 Parcel 捆绑时,S3 不是构造函数
- python - 如果满足某些 GroupBy 条件,则从原始 Pandas 数据框中删除行
- google-chrome - 谷歌图表仅在浏览器缩放为 100% 时呈现