我正在react-native中创建一个屏幕,我必须在父 View 上显示文本。如何让整个文本显示出来?
一开始我认为这是文本不换行的问题,所以我从一个问题 here 尝试了这个解决方案
<View style={{flexDirection:'row'}}>
<Text style={{flex: 1, flexWrap: 'wrap'}}> You miss fdddddd dddddddd
You miss fdd
Another line
and another one
</Text>
</View>
然后我尝试了numberOfLines={1}
这是我的代码
<View style={{ width: '100%', height: '15%', position: 'absolute', alignSelf: 'center', backgroundColor: 'rgba(255, 255, 255, 0.4)', borderRadius: 5, marginTop: '90%', }}>
<Text style={{ width: '80%', backgroundColor: 'transparent', alignSelf: 'center', textAlign: 'center', fontSize: 18, color: '#005F6A', marginTop: '5%' }}>
{`Text the first &
Text the second &
text the third`}
</Text>
</View>
我希望渲染所有文本,但只渲染第一行
最佳答案
文本渲染正确,但当您放置了属性 width=80%
时,它必然会将内容换行到新行。我在父 View 中使用了红色,以使文本更加清晰。请尝试运行以下代码,如果您遇到任何问题,请告诉我。我会尽力帮助你的伴侣。
<View style={{ backgroundColor: 'red', borderRadius: 5 }}>
<Text style={{ backgroundColor: 'transparent',
textAlign: 'center',
fontSize: 18,
color: '#005F6A',
marginTop: '5%'
}}>
Text the first & Text the second & text the third, Text the fourth & text the fifth
</Text>
</View>
关于javascript - 有没有办法可以将 Text 组件的全部内容包装在 React-Native 的父 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56017863/