【问题标题】:Android ImageView radial gradient similar to a spotlight?Android ImageView 径向渐变类似于聚光灯?
【发布时间】:2013-10-04 21:30:20
【问题描述】:

我正在尝试使我的 imageview 具有径向渐变背景,该背景从纯白色变为外部的透明白色。这是我用作 ImageView 背景的 SHAPE 定义。问题是我的背景最终得到了一个纯白色圆圈,而不是我想要的半透明边缘:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
        android:startColor="#ffffff00"
        android:endColor="#ffffffff"
        android:centerX="50%"
        android:centerY="50%"
        android:gradientRadius="50%"
        android:type="radial"/>
    <corners 
        android:bottomRightRadius="20dp" 
        android:bottomLeftRadius="20dp" 
        android:topLeftRadius="20dp" 
        android:topRightRadius="20dp"/> 

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    好的,我想通了。我有两个错误:第一个是 gradientRadius 不支持百分比,第二个是 startColor 和 endColor 中的前两个位置是透明度值。这是 AARRGGBB 不是 RRGGBBAA。这是固定的形状定义:

    <?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <gradient 
            android:startColor="#ffffffff"
            android:endColor="#00ffffff"
            android:gradientRadius="36"
            android:type="radial"/>
        <corners 
            android:bottomRightRadius="20dp" 
            android:bottomLeftRadius="20dp" 
            android:topLeftRadius="20dp" 
            android:topRightRadius="20dp"/> 
    </shape>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多