android - BorderColor 没有在 android 上选择 linearGradient 颜色

标签 android css react-native colors linear-gradients

我试图创建一个圆圈,里面有一个图像,它的边框是彩色的,这就是我使用 LinearGradient 的原因。

我正在使用这个指南:

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

})

最佳答案

您应该为 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',
  }

关于android - BorderColor 没有在 android 上选择 linearGradient 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56375004/

相关文章:

react-native - 在应用程序加载时缓存完整的图像文件夹(React Native Expo)

android - 如何创建没有边距的 ViewPager?

android - 输出 jar 是空的。您是否指定了正确的 '-keep' 选项?

html - 如果第一个不起作用,有没有办法使用后备图像 URL?

css - 如何找到一个 css 类,它有另一个 css 类作为兄弟

html - Css - 让下拉菜单向下滚动

react-native - 如何在 Expo 中使用 DocumentPicker 选择多个文件?

javascript - React Native - 如何水平滑动卡片并给它们留出边距

android - 错误 :"Configuration ' compile' 已过时并已替换为 'implementation' .", even though no ' compile' present in gradle

android - 我可以直接在 ContentProvider 的 open ParcelFileDescriptor openFile() 中传递我的 InputStream 吗?