2012-05-31 103 views
1

是否有可能使用drawables創建具有向外輻射白色模糊的黑色背景?Android - 不透明度淡化可繪製

這是最終產品的樣子,雖然齒輪是一個ImageViwe,而文本是一個TextView,我希望黑色+白色模糊是一個可繪製的,我可以分配給含的LinearLayout:

enter image description here

下面是佈局(最終在GridView使用)的代碼。我想在的LinearLayout的背景設置爲上述可繪製如果可能的話:

<?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> 

回答

9

當然,以下是徑向漸變繪製,將被用作背景。更改顏色/漸變半徑以獲得所需的效果。 (在繪製文件夾 「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> 

應用它,使用下面一行在你的LinearLayout

android:background="@drawable/radialbg">