2014-11-21 110 views
3

我有一个图像,我想在底部添加黑色透明以显示文本细节。从服务器,我会得到正常的图像,我想像下面这样转换它。在下面的图片中,您可以看到图像的底部有黑色透明。如何在android中的图像上放置黑色透明

enter image description here

回答

16

试试这个

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/ur_image" /> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/gradient_bg" > 
</FrameLayout> 

和gradient_bg.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <gradient 
     android:angle="90" 
     android:centerColor="#59000000" 
     android:endColor="@android:color/transparent" 
     android:startColor="#000000" /> 
</shape> 
+0

节约了大量hours..thanks的@shijil – CrazyMind 2016-09-26 10:30:33

+0

这救了我的命。谢谢 :) – Grcn 2017-09-19 03:59:04

3

将使用的FrameLayout图像上方的另一个ImageView的并将其设置为源:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 

<gradient 
    android:angle="270" 
    android:startColor="#8000" 
    android:endColor="#0000"/> 

</shape> 
1

这可以通过创建gradients.check this

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape> 
      <gradient 
       android:startColor="#4C4C43" 
       android:endColor="#B8B894" 
       android:angle="270" /> 
     </shape> 
    </item> 
</selector 

>

可以使用
0

您可以使用alpha属性

android:alpha="0.0" thats invisible 
android:alpha="0.5" see-through 
android:alpha="1.0" full visible