简体   繁体   中英

Android Make transparent half of view

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?

在此处输入图片说明

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM