Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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
Reactjs 如何使家长';s的宽度是否用React Native包装其内容?_Reactjs_React Native - Fatal编程技术网

Reactjs 如何使家长';s的宽度是否用React Native包装其内容?

Reactjs 如何使家长';s的宽度是否用React Native包装其内容?,reactjs,react-native,Reactjs,React Native,我是个新来的土生土长的人,所以这可能是个愚蠢的问题 我想要得到的是这样的东西: 其中我有一个父视图,有两个子视图,图像和文本,垂直向左对齐。我希望父视图只覆盖其子视图的宽度。但我得到的是: 父视图延伸到移动屏幕的整个宽度 这是我的密码: render () (<View style={{backgroundColor: '#333333'}}> <Image source={btnImageSource} /> <Text>Some label&l

我是个新来的土生土长的人,所以这可能是个愚蠢的问题

我想要得到的是这样的东西:

其中我有一个父视图,有两个子视图,图像和文本,垂直向左对齐。我希望父视图只覆盖其子视图的宽度。但我得到的是:

父视图延伸到移动屏幕的整个宽度

这是我的密码:

render () (<View style={{backgroundColor: '#333333'}}>
  <Image source={btnImageSource} />
  <Text>Some label</Text>
</View>);
render()(
一些标签
);

类似于Android的“包装内容”宽度值。

您可以使用
flex
完成此操作。我发现这在使用flex时非常有用

一个好的起点是创建一个父视图,它是
flexDirection:row,justifyContent:flexstart

render () (
    <View style={{justifyContent: 'flex-start', flexDirection: 'row'}}>
        <View style={{backgroundColor: '#333333'}}>
            <Image source={btnImageSource} />
            <Text>Some label</Text>
        </View>
    </View>
);
render()(
一些标签
);