BorderColor not picking the linearGradient color on android

一世执手 提交于 2019-12-30 11:55:51

问题


Im trying to create a circle with an image inside it that its border is colourful that's why I used LinearGradient.

I was using this guide:

https://codeburst.io/linear-gradient-for-border-color-in-react-native-5bcab3eea1c9

the problem that in iOS its working fine as you can see in this image:

https://imgur.com/a/Tz0uEcC

but on android the when I use borderWidth and choosing borderColor of transparent the borderColor looks like shadow and not picking the LinearGradient color from some reason...

here is the android: https://imgur.com/a/qG1LJBt

what am I doing wrong?


        <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',
  },

})

Thank you for the help


回答1:


You should add style to the TouchableOpacity:

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

in addition change the style of profilePhotoContainer to:

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',
  }



来源:https://stackoverflow.com/questions/56375004/bordercolor-not-picking-the-lineargradient-color-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!