可以使用 Flex 布局和 borderRadius 属性来实现。

首先,使用 Flex 布局将两个圆圈放在同一行,并使用 justifyContent 和 alignItems 属性将它们垂直居中。然后,使用 borderRadius 属性将圆圈变成圆形。

代码示例:

<View style={{flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}> 
  <View style={{width: 20, height: 20, borderRadius: 10, backgroundColor: 'red', marginRight: 10}} /> 
  <View style={{width: 20, height: 20, borderRadius: 10, backgroundColor: 'red', marginLeft: 10}} /> 
</View>

其中,width 和 height 属性设置圆圈的大小,borderRadius 属性设置圆角半径,backgroundColor 属性设置颜色,marginRight 和 marginLeft 属性设置圆圈之间的间距。

在一个不确定高度的 View 中,可以将上述代码放入一个父 View 中,并设置父 View 的 flex 属性为 1,让它占据整个容器的空间。

代码示例:

<View style={{flex: 1}}> 
  <View style={{flexDirection: 'row', justifyContent: 'center', alignItems: 'center'}}> 
    <View style={{width: 20, height: 20, borderRadius: 10, backgroundColor: 'red', marginRight: 10}} /> 
    <View style={{width: 20, height: 20, borderRadius: 10, backgroundColor: 'red', marginLeft: 10}} /> 
  </View> 
</View>

这样就可以在一个不确定高度的 View 中画两竖排圆圈填充这个容器了。


原文地址: https://www.cveoy.top/t/topic/oYVG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录