React Native无法调整View宽度

发布于 2025-01-20 11:27:48 字数 1814 浏览 1 评论 0原文

我正在尝试创建3个按钮。该按钮之一将具有长文字。我希望他们具有相同的宽度。由于某种原因,当我尝试更改时,宽度不会改变。 在这里看起来如何

看起来宽度是包裹内容。如何解决它,为什么这样?

app.js

import React from 'react';

export default function App() {
  return (
    <CustomScrollView >
      <View2>
        <BtnFeature activeOpacity={0.9} onPress={undefined}>
          <FontAwesome name="user" size={40} color='#fff' />
          <PanelText>Text 1</PanelText> 
        </BtnFeature>
        <BtnFeature activeOpacity={0.9} onPress={undefined}>
          <FontAwesome5 name="user" size={40} color='#fff' />
          <PanelText>Very Long Text</PanelText> 
        </BtnFeature>
        <BtnFeature activeOpacity={0.9} onPress={undefined} >
          <FontAwesome5 name="user" size={40} color='#fff' />
          <PanelText>Text 3</PanelText> 
        </BtnFeature>
      </View2>
    </CustomScrollView>
  );
}

styles.js

export const CustomScrollView = styled.ScrollView`
    margin-top: ${StatusBarHeight - 10}px;
    flex: 1;
    background-color: ${white};
`;

export const PanelText = styled.Text`
    color: ${black}; 
    font-size: 14px;
    font-weight: bold;
    background-color: ${empty}; 
    text-align: center; 
`;

export const View2 = styled.View`
    background-color: ${gray};
    padding: 15px;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
`;

export const BtnFeature = styled.View`
    background-color: ${blizzardBlue};
    align-items: center;
    justify-content: center;
    padding: 10px;
    height: 100px;
    width 111px;
    border-radius: 10px;
`;

I'm trying to create 3 buttons. One of the button will have a long text. I want them to have the same width. For some reason the width doesn't change when I try to change it. Here how it looks

It looks like the width is wrap content. How to solve it and why is it like that?

App.js

import React from 'react';

export default function App() {
  return (
    <CustomScrollView >
      <View2>
        <BtnFeature activeOpacity={0.9} onPress={undefined}>
          <FontAwesome name="user" size={40} color='#fff' />
          <PanelText>Text 1</PanelText> 
        </BtnFeature>
        <BtnFeature activeOpacity={0.9} onPress={undefined}>
          <FontAwesome5 name="user" size={40} color='#fff' />
          <PanelText>Very Long Text</PanelText> 
        </BtnFeature>
        <BtnFeature activeOpacity={0.9} onPress={undefined} >
          <FontAwesome5 name="user" size={40} color='#fff' />
          <PanelText>Text 3</PanelText> 
        </BtnFeature>
      </View2>
    </CustomScrollView>
  );
}

styles.js

export const CustomScrollView = styled.ScrollView`
    margin-top: ${StatusBarHeight - 10}px;
    flex: 1;
    background-color: ${white};
`;

export const PanelText = styled.Text`
    color: ${black}; 
    font-size: 14px;
    font-weight: bold;
    background-color: ${empty}; 
    text-align: center; 
`;

export const View2 = styled.View`
    background-color: ${gray};
    padding: 15px;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
`;

export const BtnFeature = styled.View`
    background-color: ${blizzardBlue};
    align-items: center;
    justify-content: center;
    padding: 10px;
    height: 100px;
    width 111px;
    border-radius: 10px;
`;

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文