java 如何在android中的图像上放置黑色透明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27061901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put black transparent on image in android
提问by Ramesh
I've a image where i would like to add black transparent at bottom to show the text details. From the server i will get the normal images which i would like to convert it like below. In below image you can see that the bottom of the image has black transparent.
我有一张图片,我想在底部添加黑色透明以显示文本详细信息。从服务器我将得到我想像下面这样转换的普通图像。在下图中,您可以看到图像底部有黑色透明。
回答by Shijil
try this
试试这个
<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>
and gradient_bg.xml
和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>
回答by Bene
Put another ImageView above the image using a FrameLayout and set this as src:
使用 FrameLayout 在图像上方放置另一个 ImageView 并将其设置为 src:
<?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>
回答by Magesh Pandian
Use AppCompatImageView with tint attribute
使用带有 tint 属性的 AppCompatImageView
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tint="@color/black_transparent"//transparent color
android:scaleType="centerCrop"
android:src="@drawable/background_splash" />
</FrameLayout>
回答by yooneskh
You can use tints.
您可以使用色调。
<ImageView
...
android:tint:"#64000000"
.../>
回答by Garjpreet Singh
this can be used by creating 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
>
>
回答by Shreenivas Chikati
You can use alpha attribute
您可以使用 alpha 属性
android:alpha="0.0" thats invisible
android:alpha="0.5" see-through
android:alpha="1.0" full visible