React Native创建视图问题?

问题描述 投票:0回答:4

我有两个观点。 ViewA是固定大小(60 * 60),剩余空间用于ViewB。如何在React Native中创建这些视图?下图是我想要创建的示例视图。

查看我试过的代码:

<View style={{ width: '100%', height: 60, backgroundColor: 'green', flexDirection: 'row' }}> 
    <View style={{ backgroundColor: 'pink', flex: 2 }}/> 
    <View style={{ flex: 1, with: 60, height: 60, backgroundColor: 'purple', }}/>
</View>

enter image description here

reactjs react-native react-native-android react-native-ios
4个回答
1
投票

好的,这应该工作。来自react-native的import维度。

<View style={{ display: "flex", flexDirection: "row", flex: 1 }}>
        <View style={{ width: Dimensions.get("window").width - 60, backgroundColor: "pink" }}></View>
        <View style={{ width: 60, height: 60, backgroundColor: "purple" }}></View>
    </View>

0
投票

在顶部添加一些填充。

工作演示:https://snack.expo.io/Syp9bUrDm

<View style={{ width: '100%', height: 60, backgroundColor: 'green', flexDirection: 'row', paddingTop: 20 }}> 
      <View style={{ backgroundColor: 'pink', flex: 2 }}/> 
      <View style={{ flex: 1, width: 60, height: 60, backgroundColor: 'purple', }}/>
</View>

0
投票

您可以使用flex来实现此概念

<View style={{ flex:1, height: 60, backgroundColor: 'green', flexDirection: 'row' }}> 
    <View style={{ backgroundColor: 'pink', flex: 0.6 }}/> 
    <View style={{ flex: 0.4, backgroundColor: 'purple', }}/>
</View>

0
投票

尝试使用此方法

<View style={{flex:1}}>
        <View style={{ width: '100%', flex:1, height: 60, backgroundColor: 'green', flexDirection: 'row-reverse', paddingTop: 20 }}> 

            <View style={{ height: 60,width:60, backgroundColor: 'purple', }}/>
            <View style={{ height: 60,backgroundColor: 'pink', alignSelf:'stretch', flex:1 }}>

            </View> 
        </View>
      </View>

https://snack.expo.io/@saravanansivalingam/top-padding检查这个

© www.soinside.com 2019 - 2024. All rights reserved.