react-native - React Native 文本和图像并排对齐问题
问题描述
我正在尝试调整右下角的前进图标和水平对齐的文本中心,它们都在同一行中。
注意:我有可用的本地图像,但在这里我只是使用了无效图像 URL 的大小
https://snack.expo.io/rkEG55US8 (snack expo 在 iOS 上正常运行,但在 android 和 web 上运行不正常)
const styles = StyleSheet.create({
icon: {
height: "80%",
width: "10%",
marginLeft: "5%",
},
forwardIcon: { alignContent: 'flex-end' },
title: {
width: '100%', marginTop: -10, fontSize: 24, lineHeight: 28,
color: '#012169', fontFamily: 'Roboto', textAlign: 'center',
},
item: { marginVertical: 10, width: "100%", height: 130, backgroundColor: 'white', alignItems: 'center', },
})
<View style={{ backgroundColor: "#2C4B9F", flex: 1 }}>
<SafeAreaView style={{ marginTop: 40, marginLeft: 25, marginRight: 25 }}>
<View>
<TouchableOpacity style={styles.item} onPress={() => loadInBrowser('http://google.com/')}>
<Image source={require("http://via.placeholder.com/239x97.png")} />
<View style={{ flex: 1, }}>
<Text style={styles.title}>Long Longer Text<View style={styles.icon}>
<Image style={styles.forwardIcon} source={require("http://via.placeholder.com/36x36.png")} />
</View>
</Text>
</View>
</TouchableOpacity>
</View>
<View>
<TouchableOpacity style={styles.item} onPress={() => loadInBrowser('http://google.com/')}>
<Image style={{marginTop: 5}} source={require("http://via.placeholder.com/147x86.png")} />
<View style={{ flex: 1, marginTop: 5 }}>
<Text style={styles.title}>Smaller Text<View style={styles.icon}>
<Image style={styles.forwardIcon} source={require("http://via.placeholder.com/36x36.png")} />
</View>
</Text>
</View>
</TouchableOpacity>
</View>
</SafeAreaView>
</View>
想要的。
到现在实际达到
解决方案
你不能在一个两元素的 flex 视图中居中一个元素。您可以在底部视图中使文本居中,并使前进图标位置绝对位于右下角。
推荐阅读
- javascript - React / Material-Ui:表单提交后打开模态/对话框
- python - 从 bs4.element 获取特定项目
- javascript - Azure 函数:如何访问 context.res.body 的内容?
- nginx - 如何在 DaemonSet 中将文件挂载为 ConfigMap?
- azure - 如何从 Azure AD 登录面板中删除“阅读您的邮件”同意?
- wavelet - 为什么双树复小波具有位移不变性?
- php - Woocommerce“简单产品类型”更改零价格产品的价格文本,无价格产品
- python - Python 返回带有 Jinja2 设置标签的“无效语法”
- python - 是否可以有无头模式和浏览器扩展?在 Selenium 和 python 中)
- c# - 为什么使用实体框架首次调用数据库需要更长的时间,即使之前已经调用过这个数据库?