如何制作透明渐变?

80

我有以下渐变:

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient 
            android:startColor="#ECECEC"
            android:centerColor="#F6F6F4"
            android:endColor="#F8F8F6"
            android:angle="90"
            android:dither="true"
         />
    </shape>

我希望这个东西是透明的,因为在我的ListView中,我将其设置为我的ListSelector:

<ListView android:layout_width="fill_parent"
                android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/ARListView" 
                android:background="@drawable/transparent_background" 
                android:cacheColorHint="#00000000" android:drawSelectorOnTop="true" 
                android:listSelector="@drawable/stocks_selected_gradient">
</ListView>
3个回答

144

只需使用8位颜色值,例如#FFF8F8F6,其中前两个字符是透明度值。FF表示完全不透明,00表示完全透明。


4
建议使用@android:color/transparent,而不是#00xxxxxx。 - The Hungry Androider

4

android:background="#00000000" android:cacheColorHint="#00000000"

这将使其透明,然而,这是为了使其完全透明...


2
您可以尝试以下代码:
<gradient android:startColor="#hex_of_any_color" android:endColor="#00000"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接