Android Make transparent half of view

2019-05-21 03:35发布

问题:

I can make an image button like "1" with android xml and bitmap repeat.

But I want to make it like "2" (half transparent) with android xml. How can I make it?

回答1:

Create half_transparent_bg.xml as follows:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
    android:angle="180"
    android:endColor="#00ffffff"
    android:startColor="#ffffffff"/>
</shape>

You can change the background of the image button to this drawable

or if you want to stack it to the bitmap repeat put the bitmap with the shape drawable above in layer-list

EDIT:

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

<item>
    <bitmap
        android:src="@drawable/close"
        android:tileMode="repeat" />
</item>
<item>
    <shape>
        <gradient
            android:angle="180"
            android:endColor="#00ffffff"
            android:startColor="#ffffffff" />
    </shape>
</item>

Where you can put your red stripe instead of close



回答2:

This is my project view. I want remove solid white color and keep white strips. transparent half of strips.

http://i.stack.imgur.com/H5vJi.png

and i is my xml:

<?xml version="1.0" encoding="utf-8"?>

<item>
    <shape>
        <gradient
            android:angle="0"
            android:endColor="#FFFFFFFF"
            android:startColor="#00FFFFFF" />
    </shape>
</item>
<item>
    <bitmap
        android:antialias="true"
        android:dither="true"
        android:filter="true"
        android:src="@drawable/ww"
        android:tileMode="repeat" >
        <shape>
        </shape>
    </bitmap>
</item>