反应本地弹性指导:' row'不起作用

发布于 2025-02-12 11:42:44 字数 757 浏览 2 评论 0原文

我试图将这些项目名称列为一排 - 将它们放置在水平上,但它不起作用。我不知道原因。我真的很感谢您的帮助

const Text = () => {

 const Menu = [
 {'id':1,
  'menuName':'whatever',
},

{'id':2,
'menuName':'whatever',
},

{'id':3,
'menuName':'whatever...',
},
];
  return (
    <View style={styles.container}><Text 
    >Test   
    </Text>
    {Menu.map((menuItems) => (
              <View style={styles.menuName}  key={menuItems.id} >
                <Text>{menuItems.menuName}</Text>
              </View>
            ))}
    </View>
  )
}
const styles = StyleSheet.create({
  container :{
    flex:1
 },
  menuName:{
    flexDirection: 'row',
    height: 48,
    width: '100%',
    borderWidth: 1,
    padding: 10,
  }

});

I am trying to list these itemsNames into a row- put them horizontaly, but it is not working. I can't figure out the reason why. I would really appreciate some help

const Text = () => {

 const Menu = [
 {'id':1,
  'menuName':'whatever',
},

{'id':2,
'menuName':'whatever',
},

{'id':3,
'menuName':'whatever...',
},
];
  return (
    <View style={styles.container}><Text 
    >Test   
    </Text>
    {Menu.map((menuItems) => (
              <View style={styles.menuName}  key={menuItems.id} >
                <Text>{menuItems.menuName}</Text>
              </View>
            ))}
    </View>
  )
}
const styles = StyleSheet.create({
  container :{
    flex:1
 },
  menuName:{
    flexDirection: 'row',
    height: 48,
    width: '100%',
    borderWidth: 1,
    padding: 10,
  }

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2025-02-19 11:42:44

原因。

的 - 方向将应用于查看(容器)

请进行以下样式更改。

container :{
  flex:1,
  flexDirection: 'row',
},
menuName:{
  height: 48,
  width: '100%',
  borderWidth: 1,
  padding: 10,
}

要更多地研究flex href =“ https://reaectnative.dev/docs/flexbox” rel =“ nofollow noreferrer”> link。

Reason for not to work.

In order to arrange the items in a view, you need to set flexDirection='row' in your case items inside your View(Container) needed to be arranged horizontally so the flex-direction will be applied to View(Container)

Please make the following changes in style it will work.

container :{
  flex:1,
  flexDirection: 'row',
},
menuName:{
  height: 48,
  width: '100%',
  borderWidth: 1,
  padding: 10,
}

To study more about flex please follow this link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文