Add gradient to imageview
You need two layers: An ImageView
, and a View
on top of that with your gradient as android:background
. Put these two View
s in a FrameLayout
:
<FrameLayout
... >
<ImageView
...
android:src="@drawable/trend_donald_sterling" />
<View
...
android:background="@drawable/trending_gradient_shape"/>
</FrameLayout>
Simply set the alpha value in your gardient.xml:
Your imageView:
android:background="@drawable/trend_donald_sterling"
android:src="@drawable/trending_gradient_shape"
Your gradient xml file:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#00ffffff"
android:startColor="#aa000000"
android:centerColor="#00ffffff" />
<corners android:radius="0dp" />
</shape>
In the color value, the first two places after # correspond to the alpha value, while the rest are the actual color value in R G B format, two for each.
try using the "foreground" attribute in your imageview
<ImageView
...
android:src="@drawable/trend_donald_sterling"
android:foreground="@drawable/trending_gradient_shape" />
it worked for me.