Josh
Josh

Reputation: 12566

Android - Opacity Fade Drawable

Is it possible, using just drawables to create a black background with an outward radiating white blur?

Here is what the final product will be, and whilst the gear is an ImageViwe, and the text is a TextView, I'd like to have the black + white blur be a single drawable, that I can assign to the containing LinearLayout:

enter image description here

Here is the code for the layout (eventually used in a GridView). I'd like to set the LinearLayout's background to the aforementioned Drawable if possible:

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

Upvotes: 1

Views: 4688

Answers (1)

wdziemia
wdziemia

Reputation: 1459

Sure is, the following is the radial gradient drawable and will be used as the background. Change the colors/gradient radius to get the desired effect. ( create xml file in drawable folder "radialbg", or which name you prefer)

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

to apply it, use the following line in your linearlayout

android:background="@drawable/radialbg">

Upvotes: 10

Related Questions