android - 使用 FlatList 裁剪图像
问题描述
图像被裁剪,我该如何防止这种情况发生?请注意,它只出现了图像的一半。这是一个安卓设备。我不知道这是否也发生在IOS中。但是对于android的修复会很棒
我的 FlatList 组件
import React from 'react';
import { Text, View, StyleSheet, FlatList, Image } from 'react-native';
const shows_first = [
{
key: 1,
name: 'Suits',
image: 'https://static.tvmaze.com/uploads/images/medium_portrait/0/2432.jpg'
},
{
key: 2,
name: 'Modern Family',
image: 'https://static.tvmaze.com/uploads/images/medium_portrait/0/628.jpg'
},
]
const renderItem = (item) => {
return (
<Image style={{ width: 120, height: 100 }} source={{ uri: item.image }} />
)
}
const List = () => {
return (
<View style={{ flex: 1, marginTop: 110 }}>
<FlatList
horizontal={true}
ItemSeparatorComponent={() => <View style={{ width: 5 }}></View>}
renderItem={({ item }) => renderItem(item)}
data={shows_first}
></FlatList>
</View>
)
}
export default List;
解决方案
您应该使用调整大小模式来选择要显示图像的方式。如果您确定所有图像都将成为海报,则最好给出适合图像的高度和宽度。检查下面的代码
const renderItem = (item) => {
return (
<Image style={{ width: 80, height: 120 ,resizeMode: 'center'}} source={{ uri: item.image }} />
)
}
推荐阅读
- spring - @RequestMapping 方法中的前提条件?
- sql - 加入前与加入后的 PostgreSQL 聚合性能差异
- javascript - 通过 JS 按百分比重定向
- javascript - Angular 6 日历模板解析错误:无法绑定到“视图”,因为它不是“div”的已知属性
- angular - 如何在angular2+中为configfactory函数编写茉莉花单元测试
- android - 如何从Android中的片段点击打开片段
- angular - Angular 与 RxJS:确保使用 http.get 的服务构造函数在调用方法之前完成
- angular - Angular Material Theming - 无需重建即可动态添加主题
- python - `firebase-admin` ModuleNotFound 导入
- c# - 本地(非网络)计算机上的 SQL Server Express 上的错误 26