Android Make transparent half of view

2019-05-21 03:58发布

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?

enter image description here

2条回答
Luminary・发光体
2楼-- · 2019-05-21 04:24

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

查看更多
Root(大扎)
3楼-- · 2019-05-21 04:31

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>

查看更多
登录 后发表回答