How to make black transparent image in android

I have an image where I would like to add a black transparent bottom to show the details of the text. From the server, I will get normal images that I would like to convert, as shown below. In the bottom image, you can see that the bottom of the image is black transparent.

enter image description here

+4
source share
4 answers

try it

<FrameLayout 
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/ur_image" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient_bg" >
</FrameLayout>

and gradient_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <gradient
        android:angle="90"
        android:centerColor="#59000000"
        android:endColor="@android:color/transparent"
        android:startColor="#000000" />
</shape>
+18
source

Place another ImageView above the image using FrameLayout and set this as src:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
    android:angle="270"
    android:startColor="#8000"
    android:endColor="#0000"/>

</shape>
+3
source

, gradients.check this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:startColor="#4C4C43"
                android:endColor="#B8B894"
                android:angle="270" />
        </shape>
    </item>
</selector
< →
+1
source

You can use alpha attribute

android:alpha="0.0" thats invisible
android:alpha="0.5" see-through
android:alpha="1.0" full visible
0
source

All Articles