【问题标题】:Android - Opacity Fade DrawableAndroid - 不透明渐变可绘制
【发布时间】:2012-05-31 16:07:28
【问题描述】:

是否可以仅使用可绘制对象来创建带有向外辐射的白色模糊的黑色背景?

这是最终产品,虽然齿轮是 ImageViwe,文本是 TextView,但我希望将黑白模糊设置为单个可绘制对象,我可以将其分配给包含线性布局:

这是布局的代码(最终在 GridView 中使用)。如果可能的话,我想将 LinearLayout 的背景设置为上述 Drawable:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="#000000"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/tile_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:adjustViewBounds="true"
        android:contentDescription="@string/temp_image"
        android:src="@drawable/ic_logo" />

    <TextView
        android:id="@+id/tile_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

【问题讨论】:

    标签: android xml resources drawable


    【解决方案1】:

    当然,下面是径向渐变drawable,将用作背景。更改颜色/渐变半径以获得所需的效果。 (在可绘制文件夹“radialbg”中创建 xml 文件,或者您喜欢的名称)

    <?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="270"
        android:type="radial"/>
    
    </shape>
    

    要应用它,请在您的线性布局中使用以下行

    android:background="@drawable/radialbg">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-13
      • 2011-07-26
      相关资源
      最近更新 更多