<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="150dp">
<ImageView
android:id="@+id/img_banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:background="@mipmap/icon_temp"/>
<View
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/trending_gradient_shape"/>
</FrameLayout>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient android:angle="90"
android:endColor="#00ffffff"
android:startColor="#670032"
android:centerColor="00ffffff"
android:type="linear"/>
</shape>
public static Bitmap addGradient(Bitmap originalBitmap,int templateColor) {
int width = originalBitmap.getWidth();
int height = originalBitmap.getHeight();
Bitmap updatedBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(updatedBitmap);
canvas.drawBitmap(originalBitmap, 0, 0, null);
Paint paint = new Paint();
LinearGradient linearGradient = new LinearGradient(0, height / 4, 0, height * 3 / 4,
Color.TRANSPARENT, templateColor, Shader.TileMode.CLAMP);
paint.setShader(linearGradient);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
canvas.drawRect(0, 0, width, height, paint);
return updatedBitmap;
}