reactjs - React native - 如何用文本包装视图?
问题描述
像上面的截图一样,我希望用文本包裹视图(8.5)。
这是我尝试过的:
<View style={{flexDirection:'row'}>
<View style={{backgroundColor:'grey', padding:5, borderRadius:5, flexWrap:'wrap'}>
<Text style={{fontSize:12, fontWeight:'bold'}>
{item.score}
</Text>
</View>
<Text style={{fontSize:14, fontWeight:'bold', color:'black'}>{item.title}</Text>
</View>
在上面的代码中,Text 没有包裹乐谱视图,而是并排放置,如下所示:
如何确保视图被文本包裹?谢谢
---- Edit @Gaurav Roy's answer产生以下结果,除了背景颜色之外,哪些样式不适用于文本组件
解决方案
或者试试这个:
<View style={{ flex: 1, alignItems: "flex-start" }}>
<Text style={{ fontSize: 14, fontWeight: "bold", color: "black" }}>
<View
style={{ backgroundColor: "grey", padding: 5, borderRadius: 5 }}
>
<Text
style={{
fontSize: 12,
fontWeight: "bold"
}}
>
8.5
</Text>
</View>
this is a good example of how things can be achieved in the lord of
the rings
</Text>
</View>
推荐阅读
- javascript - 在 gatsby-node.js 构建期间获取数据并在运行时检索数据并通过 graqhql 呈现
- c# - C#插入Access数据库不工作并且没有异常或错误
- mongodb - 在 java spring boot 中使用 MongoDB $arrayToObject 和 $map 运算符
- reactjs - reactjs 中 ngClass.xs 或 md 的相关代码
- javascript - TypeError: (0 , _css.default) 不是函数
- c++ - C++ 非公共助手类和内联代码
- javascript - 我应该如何从正确编码的 GraalJS 脚本引擎获取脚本输出?
- .net - 找不到框架“Microsoft.AspNetCore.App”,版本“3.1.3”
- azure-devops - Azure Pipelines:等待触发的管道完成(Chain Builds Awaiter)
- javascript - 根据键值合并对象数组