【问题标题】:stretching component using left and right in react native在本机反应中使用左右拉伸组件
【发布时间】:2021-11-29 22:47:27
【问题描述】:

我正在尝试使用leftright 拉伸我的<View> 组件

我知道如何在 html 和 css 中做到这一点:

.testing{
  background-color: orange;
  position: absolute;
  left: 100px;
  right: 20px;
}
 <div class="testing"> 
  Hello there
 </div>

但是如何在 react native 中实现相同的结果?

编辑
我试过了,但它不起作用:

export default function App() {
  return (
    <View style={styles.container}>
      <View style={{ left: 100,right: 20,height:50,position: 'absolute', backgroundColor: 'orange'}}><Text>hello there</Text></View>
    </View>
  );
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
      },
    });

【问题讨论】:

  • 只要你使用css,方法都是一样的
  • @Viira 我厌倦了,但它不起作用,我已经对帖子进行了编辑,让我知道那段代码是否适合你
  • 你为什么在View里面使用View

标签: javascript html css react-native


【解决方案1】:

我测试了您的代码,它对我有用。尝试在新项目中重新安装并粘贴代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-19
    • 2020-02-02
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 2018-08-12
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多