reactjs - 如何处理 React-native 中的溢出元素?
问题描述
<View></View>
当它们的长度大于容器的长度时,如何在 react-native 中使用 flex 使内部的任何元素自行排列?
下面是我的代码:
const FilmCasts = ({ artists }) => (
<View style={{ flex: 1, flexDirection: 'row', }}>
{artists.map(artist => (
<Image
key={cast.name}
source={{ uri: artist.img }}
style={{ width: 80, height: 100 }}
/>
))}
</View>
);
这就是我要的。我想让第 5 和其他人在达到屏幕宽度限制后自动低于第一行,就像 HTML 通常做的那样
但是相反,这就是我在 React Native 中得到的结果,<Image>
元素继续呈现在其父级宽度之外
解决方案
您可以使用道具flexWrap:'wrap'
来包装元素。flexWrap 控制子元素在到达 flex 容器的末端后是否可以环绕。更多在这里
const FilmCasts = ({ artists }) => (
<View style={{ flex: 1, flexDirection: 'row',flexWrap:'wrap' }}>
{artists.map(artist => (
<Image
key={cast.name}
source={{ uri: artist.img }}
style={{ width: 80, height: 100 }}
/>
))}
</View>
);
推荐阅读
- kubernetes - 将 Minikube 连接到 Sysdig 时“等待第一个节点连接...”
- c# - 如何在 asp mvc 中更新 MDB 管理模板资产?
- javascript - 在脚本 src 中传递变量
- angular - Angular 7 - 在 Azure AD 身份验证后获取登录用户名
- sql - 将学生的分数转换为相应的成绩
- javascript - 如何使用 ajax jquery 方法获取带有复选框的 json 值?
- python - django import 我无法在我的项目文件中创建主文件
- c++ - 'checkCudaErrors' 未在此范围内声明
- html - 在网页上定位 3 个 Bootstrap Jumbotron
- java - 通过用户输入保存音频文件android