react-native - 在 React Native 中,在文本中间垂直对齐图标
问题描述
我知道有人问过类似的问题,并且我已经审查了很多,但他们无法为我的案例提供解决方案。
这是我的一段代码。
<View style={{backgroundColor: 'white', flexDirection: 'row', paddingHorizontal: 20, paddingVertical: 50}}>
<View style={{flexDirection: 'row', flex: 1, flexWrap: 'wrap'}}>
<Text>Some Text some text some text (
<Text style={{fontSize: 32}}>A</Text>
) Some Text some text some text
</Text>
{/*<Text>Some Text some text some text(</Text>*/}
{/*<Text style={{fontSize: 32}}>A</Text>*/}
{/*<Text>) Some Text some text some text</Text>*/}
</View>
<TouchableOpacity onPress={() => {}} style={{backgroundColor: 'red', justifyContent: 'center'}}>
<Text style={{fontSize: 32, alignSelf: 'center'}}>X</Text>
</TouchableOpacity>
</View>
下面是结果。
“A”和“X”是图标......不同大小的字体,我没有问题将“X”与文本对齐......问题在于“A”......
下面是预期的结果。
我能得到的最好的就是这个https://codesandbox.io/s/react-native-1y0q4但是如果宽度不够,flexWrap 会切断句子
解决方案
例如,在 CSS 中,您可以获得宽度vertical-align:sub;
,试试宽度
<Text style={{fontSize: 32, verticalAlign: 'baseline' }}>A</Text>
推荐阅读
- usrp - 使用 USRP N210 进行 QPSK 解调
- django - Django 网站突然要求用户清除 cookie 以获取 CSRF 令牌
- python-3.x - 无法使用 DearPyGui 函数,例如 set_main_window_size 或 add_drawing
- javascript - 使用 socket.io 和 node 作为后端。this.emit 在这里是什么意思?
- apache-spark - 如何在 Spark 中启用 Parquet 页面索引统计信息
- java - Cucumber - 即使所有依赖项使用相同的版本,也没有找到后端
- vb.net - 如何在 vb.net 中为其宽度着色树视图节点?
- python - 如何从 10fastfingers 中提取我的打字数据?
- angular - 如何将 WebdriverIO 的浏览器对象传递给 SeleniumWebDriverHarnessEnvironment 以进行线束加载器(@angular/cdk/testing)
- python - 在 BeautifulSoup 中循环