React Native BorderColor未在android上拾取线性渐变颜色

bjg7j2ky  于 2023-01-14  发布在  React
关注(0)|答案(1)|浏览(112)

我试图创建一个圆圈内的图像,其边界是彩色的,这就是为什么我用线性梯度。
我使用了以下指南:
https://codeburst.io/linear-gradient-for-border-color-in-react-native-5bcab3eea1c9
在iOS中运行正常的问题,如下图所示:
https://imgur.com/a/Tz0uEcC
但是在Android上,当我使用BorderWidth并选择透明的BorderColor时,BorderColor看起来像阴影,并且出于某种原因没有选择LinearGradient颜色。
这是机器人:https://imgur.com/a/qG1LJBt
我做错了什么?

<LinearGradient
          colors={['#ac8af8', '#cca5e7']}
          start={{ x: 0.0, y: 1.0 }} end={{ x: 1.0, y: 1.0 }}
          style={styles.profilePhotoContainer}
        >
          <TouchableOpacity onPress={this.handleEditProfileImage.bind(this)}>
            <Image
          style={[styles.profileImage]}
          source={this.state.profilePhoto}
        />
          </TouchableOpacity>
        </LinearGradient>

const styles = StyleSheet.create({
profilePhotoContainer: {
    zIndex: 5,
    position: 'absolute',
    top: Dimensions.get('window').height * .13,
    left: Dimensions.get('window').width / 2 - Dimensions.get('window').width * .13,
    elevation: 4,
    borderRadius: 75,
    borderWidth: 4,
    overflow: "hidden" ,
    borderColor: 'transparent',
  },
profileImage: {
    zIndex: 5,
    width: 100,
    height: 100,
    borderWidth: 1,
    borderColor: 'transparent',
    backgroundColor: '#FFF',
    flex:1,
    resizeMode:'contain',
  },

})
7z5jn7bk

7z5jn7bk1#

您应向TouchableOpacity添加样式:

style={{
  width: 100,
  height: 100, backgroundColor: 'transparent', overflow: "hidden", borderRadius: 50, flex: 1}}

此外,将profilePhotoContainer的样式更改为:

profilePhotoContainer: {
    zIndex: 5,
    position: 'absolute',
    top: Dimensions.get('window').height * .13,
    left: Dimensions.get('window').width / 2 - Dimensions.get('window').width * .13,
    elevation: 4,
    borderRadius: 75,
    padding: 5,
    overflow: "hidden",
    borderColor: 'transparent',
  }

相关问题