javascript - 有没有办法可以将 Text 组件的全部内容包装在 React-Native 的父 View 中?

标签 javascript reactjs react-native textview

我正在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/

相关文章:

javascript - 从 JSON 数组获取第一项时出现问题

javascript - 使用 Thumbs_up gem 在 Rails 4 中进行 AJAX 化投票

javascript - KendoUI 条形图 - PlotArea 未按假设工作

reactjs - 无法从上下文中解构对象的属性

javascript - 在 React Native 中并排显示图像和文本

javascript - 当我使用随机数时,为什么我无法绕过 CSP 阻止 nunjucks 中的 javascript 代码

reactjs - nextjs 在构建期间提示未定义的读取属性

reactjs - 配置多个下一个插件 : withMDX, withBundleAnalyzer

android - 世博会使用Windows 10在Android模拟器上运行

ios - React Native - 从 fetch() JSON 渲染多个元素?