回答

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

我希望你明白我想说什么。