【问题标题】:justifyContent not applying in View React NativejustifyContent 不适用于 View React Native
【发布时间】:2021-02-19 04:37:24
【问题描述】:

出于某种原因,在此视图中, justify 内容标记不适用于我的视图?我尝试在 modalScreen 视图中应用它,但这也不起作用。有什么想法吗?

function BottomPopup() {
  return (
    <View style={styles.modalScreen}>
      <View style={styles.topbar}>
        <MaterialCommunityIcons name="arrow-left" size={24} color="black" />
        <Text>Create Post</Text>
        <MaterialCommunityIcons name="content-save" size={24} color="black" />
      </View>
      <View>
        <Text>hey</Text>
        <Text>hey</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  modalScreen: {
    alignItems: "center",
  },
  topbar: {
    display: "flex",
    flexDirection: "row",
    justifyContent: "space-around",
  },
});

【问题讨论】:

  • 你想达到什么目的?你想要像 Image Create Post Image 这样的顶栏吗?像这样?

标签: android css react-native view flexbox


【解决方案1】:

在 modalScreen 样式中添加 flex:1,例如 Snack.IO

【讨论】:

    【解决方案2】:

    我必须添加宽度:“100%”,然后它才起作用

    【讨论】:

      【解决方案3】:

      import { Dimensions } from 'react-native';
      const { width, height } = Dimensions.get('window');
      
      const styles = StyleSheet.create({
        modalScreen: {
          flex:1,
          alignItems: "center",
          backgroundColor: "yellow",
        },
        topbar: {
          width: width,
          flexDirection: "row",
          justifyContent: "space-around",
          backgroundColor: "green",
        },
      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        • 2018-12-24
        • 1970-01-01
        • 2020-05-27
        • 2018-07-20
        • 2021-08-16
        • 2016-11-04
        相关资源
        最近更新 更多