7

I've a image where i would like to add black transparent at bottom to show the text details. From the server i will get the normal images which i would like to convert it like below. In below image you can see that the bottom of the image has black transparent.

enter image description here

Ramesh
  • 1,252
  • 3
  • 12
  • 30

6 Answers6

30

try this

<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>
Manohar
  • 22,116
  • 9
  • 108
  • 144
Shijil
  • 2,226
  • 18
  • 33
3

Put another ImageView above the image using a 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>
Bene
  • 724
  • 8
  • 20
2

Use AppCompatImageView with tint attribute

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v7.widget.AppCompatImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tint="@color/black_transparent"//transparent color 
        android:scaleType="centerCrop"
        android:src="@drawable/background_splash" />
</FrameLayout>
Magesh Pandian
  • 8,789
  • 12
  • 45
  • 60
1

this can be used by creating 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

>

Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
1

You can use tints.

<ImageView
  ...
  android:tint:"#64000000"
  .../>
yooneskh
  • 784
  • 7
  • 11
0

You can use alpha attribute

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