如何制作透明渐变?

Posted

技术标签:

【中文标题】如何制作透明渐变?【英文标题】:How to make transparent gradient? 【发布时间】:2011-04-18 22:13:24 【问题描述】:

我有以下渐变:

<?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_
                android:layout_ 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>

【问题讨论】:

【参考方案1】:

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

【讨论】:

最好使用@android:color/transparent 而不是#00xxxxxx【参考方案2】:

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

这将使它是透明的,但是,这是为了使它完全透明...

【讨论】:

【参考方案3】:

你可以试试下面的代码:

<gradient android:startColor="#hex_of_any_color" android:endColor="#00000"/>

【讨论】:

以上是关于如何制作透明渐变?的主要内容,如果未能解决你的问题,请参考以下文章