javascript - 将本机视图反应到下一行?
问题描述
我正在创建一个反应原生项目,在该项目中连续显示多个视图,并且在一定宽度之后,它需要转到下一行!但它不去,怎么做?
Actual Output:
word1 word-word2 word-word-word3 word-word-word4
Expected Outpu:
word1 word-word2 word-word-word3
word-word-word4
这是我的代码:
<View style={{ flexDirection :'row', marginHorizontal: 10, paddingTop: 7,
paddingBottom: 7, width: 150 }}>
<View style={{ paddingRight: 10 } }>
<Text style={{ fontSize: 12 }}>word1</Text>
</View>
<View style={{ paddingRight: 10 }}>
<Text style={{ fontSize: 12 }}>word-word2</Text>
</View>
<View style={{ paddingRight: 10 } }>
<Text style={{ fontSize: 12 }}>word-word-word3</Text>
</View>
<View style={{ paddingRight: 10 } }>
<Text style={{ fontSize: 12 }}>word-word-word4</Text>
</View>
</View>
这是我的博览会“检查这个”
请建议!
解决方案
给组件样式的父View
级:Text
flexWrap:"wrap"
<View
style={{
flexDirection: 'row',
marginHorizontal: 10,
paddingTop: 7,
paddingBottom: 7,
width: Constants.width * 0.3,
flexWrap: 'wrap'
}}>
完整示例:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
export default function App() {
return (
<View style={styles.container}>
<View style={{ backgroundColor: '#eff3f8' }}>
<View
style={{
flexDirection: 'row',
marginHorizontal: 10,
paddingTop: 7,
paddingBottom: 7,
width: Constants.width * 0.3,
flexWrap: 'wrap'
}}>
<View style={{ paddingRight: 10 }}>
<Text style={{ fontSize: 12 }}>word1</Text>
</View>
<View style={{ paddingRight: 10 }}>
<Text style={{ fontSize: 12 }}>word-word2</Text>
</View>
<View style={{ paddingRight: 10 }}>
<Text style={{ fontSize: 12 }}>word-word-word3</Text>
</View>
<View style={{ paddingRight: 10 }}>
<Text style={{ fontSize: 12 }}>word-word-word4</Text>
</View>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
工作应用程序:世博小吃
推荐阅读
- nginx - 未考虑 pagespeed_no_transform 属性
- java - 如何在 JBoss 7.0 EAP 服务器中配置 SSL/HTTPS?
- bash - 期望 Script scp 目录中的最新文件
- java - 为 char 数组定义哈希码方法的最佳方法
- flutter - 在不是其子项的 TabBar 上使用 AppBar 样式
- sql - 为什么sql server做嵌套循环
- sql-server - 与精确匹配相比,范围内的聚集索引查找速度慢(基数估计不准确)
- css - Angular 6,如何配置 CSS 设置以在所有组件上创建持久的背景颜色?
- c# - 带字符串的双块引号不起作用
- node.js - 如何在mongodb中使用像查询这样的数字字段?