【发布时间】:2022-01-09 11:51:39
【问题描述】:
我正在尝试使用 expo 在 react native 中对齐项目,但是在对齐父视图中的项目后,子视图 justifyContent 无法正常工作。例如:
<View>
<View style={{ borderBottomColor: 'black',borderBottomWidth: 3}}>
<View style={{flexDirection:'row',justifyContent:'space-between'}}>
<Text style={{ color: "#6B35E2"}}>Name</Text>
<Text style={{ fontWeight: 'bold',color: "#6B35E2"}}>Nico</Text>
</View>
</View>
<View style={{alignSelf:'flex-end'}}>
<Icon
name="fingerprint"
iconStyle={styles.iconRight}
/>
</View>
</View>
渲染following image。该图标出现在底部边框下方,我需要它位于第二个文本的右侧。重要的是要注意底部边框不能到达图标。它必须在第二个文本结束。因此,我尝试将flexDirection:row 应用于父视图,如下所示:
<View style={{flexDirection: "row"}}>
<View style={{ borderBottomColor: 'black',borderBottomWidth: 3}}>
<View style={{flexDirection:'row',justifyContent:'space-between'}}>
<Text style={{ color: "#6B35E2"}}>Name</Text>
<Text style={{ fontWeight: 'bold',color: "#6B35E2"}}>Nico</Text>
</View>
</View>
<View style={{alignSelf:'flex-end'}}>
<Icon
name="fingerprint"
iconStyle={styles.iconRight}
/>
</View>
</View>
很遗憾,it does not render correctly。图标如预期一样位于右侧,底部边框刚刚结束,但应用于子 View 的 justifyContent:space-between 属性不再起作用。有任何想法吗?这是带有expected result 的图像。重要的是底部边框不能在图标下方,它必须在之前结束。
【问题讨论】:
-
发布预期结果的图像/屏幕截图。
-
已在帖子中添加!
标签: html css reactjs react-native expo