javascript - React Native 部分组件显示出屏幕
问题描述
我使用多种渲染方法渲染按钮,但我发现很难管理它的样式。
这是我渲染按钮的代码
const [abc, setAbc] = useState([
{ type: 'aa'},{ type: 'bb'},{ type: 'cc'},{ type: 'dd'},
{ type: 'ee'},{ type: 'ff'},{ type: 'gg'},{ type: 'hh'},
{ type: 'ii'},{ type: 'jj'},{ type: 'kk'},{ type: 'll'},
{ type: 'mm'},{ type: 'nn'},{ type: 'oo'},{ type: 'pp'},
{ type: 'qq'},{ type: 'rr'},{ type: 'ss'},{ type: 'tt'},
{ type: 'uu'},{ type: 'vv'},{ type: 'ww'},{ type: 'xx'},
{ type: 'yy'},{ type: 'zz'},
])
const renderedABC = abc.map(item => {
return <Button key={item.type} title={item.type}/>;
})
它显示像
我想制作更多行并单独显示。至少它填补了底部的“空白”。
解决方案
您必须在使用flex:1样式。如果你想逐行渲染这些,那么你可以使用flexDirection : row. 默认值为“列”。在您的情况下,您不需要使用flexDirection。
renderedABC(){
return(
<View style={{flex: 1}}>
{abc.map(item => <Button key={item.type} title={item.type}/>)
</View>
)
};
推荐阅读
- wso2 - WSO2 Identity Server 使用照片编辑器 UMA webapp
- c++ - 附加调试器并以编程方式获取变量地址 Visual Studio
- javascript - 尽管使用了等待,但我没有得到我的承诺的结果
- jenkins - 在 Jenkins 中安装“JavaScript GUI Lib”插件失败
- mysql - Mysql 导入 - CSV 文件越来越大
- reactjs - 处理 useMutation 钩子中的错误的最佳方法是什么
- python - 使用python生产的内存中sqlite
- asp.net-mvc - ajax 其他参数是否为空?
- c# - 一页验证中的 Asp Net Core 2 模型
- java - 无法在 R 上将 kafka 流作为 spark 数据帧流读取/写入