回答

20

這裏溶液

圖像看起來像下面的圖片

enter image description here

代碼爲

  • 準備形狀drawabl Ë

RES /繪製/ gradient_shape.xml:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
      android:startColor="#00FFFFFF" 
      android:endColor="#FFFFFFFF" 
      android:type="linear" /> 
</shape> 

定義佈局:activity_main.xml中:

<ImageView 
    android:id="@+id/photo" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/photo" 
    android:src="@drawable/gradient_shape" /> 

這裏繪製/照片只是在可繪製jpeg的文件夾

EDIT 的詳細信息,請參閱本Tutorial

+8

這是不透明的.. – ftp27

+1

@ ffp27這是你的形象和你的形象相同的解決方案和做透明參考我的答案的教程,並希望這對你有所幫助。 –

+0

這aswer是正確的,它爲我工作! 謝謝@DixitPatel – timbillstrom

4
<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <gradient 
       android:startColor="#00FFFFFF" 
       android:endColor="#FFFFFFFF" 
       android:type="linear" /> 
    </shape> 

完美transperancy。確保View下面的漸變實際上在下面,而不只是觸摸漸變形狀視圖。

如果您有主的RelativeLayout,的ListView視圖(背景:漸變)

確保梯度查看在頂部,ListView中的,而不是一個側面。如果您的梯度處於旁邊,它將透明RelativeLayout背景顏色而不是ListView

我希望你明白我想說什麼。