react-native:borderRadius不会将组件框架正确

Mik*_*din 6 mobile reactjs react-native

borderRadius风格属性不正确地更改组件的边框.

我希望在红色背景上看到一个没有任何空白区域的绿色圆圈.相反,我看到了这一点.

在此输入图像描述

class Healthie extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.button} />
      </View>
    );
  }
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'red',
  },
  button: {
    backgroundColor: 'green',
    borderRadius: 50,
    width: 100,
    height: 100,
    textAlign: 'center'
  }
});
Run Code Online (Sandbox Code Playgroud)

react-native版本:0.17.0.

Nad*_*bit 6

要获得您正在寻找的内容,您将不得不将文本框包装在另一个视图中.更改borderRadius时,视图不会默认为另一种BG颜色:

<View style={styles.container}>
  <View style={styles.button}>
    <Text style={{ backgroundColor: 'transparent' }}>Text</Text>
  </View>
</View>

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'red',
  },
  button: {
    backgroundColor: 'green',
    borderRadius: 50,
    width: 100,
    height: 100,
    textAlign: 'center',
    flexDirection:'row', 
    alignItems:'center', 
    justifyContent:'center'
  }
});
Run Code Online (Sandbox Code Playgroud)

看看这个演示.


yfs*_*fsx 5

无需在视图中包含按钮或文本,只需将其放在您的样式上即可

overflow: hidden
Run Code Online (Sandbox Code Playgroud)

这个对我有用

  • 这适用于ios,但不适用于android.至少从RN 0.25开始.正确的答案是接受的答案. (2认同)