首页 文章

内部反射原生视图自动宽度

提问于
浏览
20

据我所知,react-native样式表不支持min-width / max-width属性 .

我有一个视图和文本 . 自动宽度中的视图不会通过继承文本元素来调整大小 .

如何解决该问题并使用文本宽度自动设置视图宽度?

我的代码是:

<View style={{backgroundColor: '#000000'}}>
      <Text style={{color: '#ffffff'}}>Sample text here</Text>
 </View>

在常见的HTML / CSS中,我会这样认识到:

<div style="background-color: #000; display: inline;">Sample text here</div>

注意:父视图上的flex:1对我没有帮助 . 文字显示为

"Sam"
"ple"
"Tex"
"t"

1 回答

  • 58

    “alignSelf”与普通的HTML / CSS中的'display:inline-block'相同,对我来说效果非常好 .

    <View style={{backgroundColor: '#000000', alignSelf: 'flex-start' }}>
     <Text style={{color: '#ffffff'}}>
      Sample text here
     </Text>
    </View>
    

相关问题