Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 水平滚动视图中的动态宽度元素_React Native - Fatal编程技术网

React native 水平滚动视图中的动态宽度元素

React native 水平滚动视图中的动态宽度元素,react-native,React Native,我有一个文本元素数组,我希望每个元素都有不同的宽度,这取决于字符长度,同时元素周围仍有相同的填充。然而,我发现滚动视图不能适应这种情况,除非我给每个映射元素设置一个宽度,否则内容就会被切断 <ScrollView horizontal={true}> foo.map((text) => { <Text style={{fontSize: 30, paddingHorizontal: "3%", marginHorizontal: "5%

我有一个文本元素数组,我希望每个元素都有不同的宽度,这取决于字符长度,同时元素周围仍有相同的填充。然而,我发现滚动视图不能适应这种情况,除非我给每个映射元素设置一个宽度,否则内容就会被切断

<ScrollView horizontal={true}>
foo.map((text) => {
   <Text style={{fontSize: 30, paddingHorizontal: "3%", marginHorizontal: "5%", backgroundColor: "white" }}>{Text}</Text>
}
</ScrollView>

foo.map((文本)=>{
{Text}
}

ScrollView是否有办法在不为每个值设置实际宽度的情况下,将边距/padidng纳入宽度考虑范围?

您可以使用FlatList进行此操作,因为ScrollView只能这样工作,您必须为每个子级设置属性。