Android:用透明度覆盖图片(jpg)

我有一个图片(jpg),我想在屏幕上显示.
此外,图片应部分覆盖透明效果.
透明盖应该是动态的.例如每一天都会显示更多的图片.
这里有一张照片来显示我的意思:

我的照片没有灰色封面,想要添加这个封面,但在不同的步骤.

有人可以给我一个提示如何做到这一点.

解决方法

您可以使用小部件:

FrameLayout是将视图叠加在一起的一般机制:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<ImageView  
    android:id="@+id/image"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/my_image"/>
<View
    android:id="@+id/overlay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</FrameLayout>

然后在Java代码中,您可以动态设置叠加层的透明度:

View overlay = (View) findViewById(R.id.overlay);
int opacity = 200; // from 0 to 255
overlay.setBackgroundColor(opacity * 0x1000000); // black with a variable alpha
FrameLayout.LayoutParams params =
    new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,100);
params.gravity = Gravity.BottOM;
overlay.setLayoutParams(params);
overlay.invalidate(); // update the view

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...