Alpha-gradient on Android

房东的猫 提交于 2019-11-28 06:54:25

Here the solution

the image look like below picture

code for that:

  • Prepare shape drawable

res/drawable/gradient_shape.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
            android:startColor="#00FFFFFF"
            android:endColor="#FFFFFFFF"
            android:type="linear" />
</shape>

Define layout: activity_main.xml:

<ImageView
    android:id="@+id/photo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/photo"
    android:src="@drawable/gradient_shape" />

here drawable/photo is just jpeg in drawables folder

EDIT for more information refer this Tutorial

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
                android:startColor="#00FFFFFF"
                android:endColor="#FFFFFFFF"
                android:type="linear" />
    </shape>

perfect transperancy. Make sure that the View below gradient is actually below and not just touching Gradient shape View.

If you have main RelativeLayout, ListView and View(Background:Gradient )

make sure that Gradient View is on top, of the ListView, and not a side. If Your gradient is aside it will be transparent by RelativeLayout Background Color and not by ListView .

i hope you understand what i want to say.

For transparency :

android:startColor="@null"

Or you can use a 8-digit hex color like that :

android:startColor="#FF000000"

The first two FF are for the alpha of the color, 00 is fully transparent and FF opaque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!