安卓:叠加图片(JPG格式)与透明度 [英] Android: Overlay a picture (jpg) with transparency

查看:209
本文介绍了安卓:叠加图片(JPG格式)与透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张照片(JPG格式),我想在屏幕上显示。 此外,该图象应该由透明的效果部分覆盖。 透明盖应该是动态的。因此,如每天多画面的显示。 下面的图片来说明我的意思:

I have a picture (jpg) that I want to display on the screen. Additionally the picture should be covered partially by a transparent effect. The transparent cover should be dynamic. So e.g. each day more of the picture is shown. Here a picture to show what I mean:

我有没有灰色封面的图片,并希望添加这个封面,但在不同的步骤。

I have the picture without the gray cover and want to add this cover but in different steps.

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

Can someone give me a hint how to do that.

推荐答案

您可以做到这一点简单地用小工具:

You can do this simply with widgets:

的FrameLayout 是一般的机构覆盖视图在另一个之上:

FrameLayout is the general mechanism for overlaying a view on top of another:

<?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 code可以动态地设置您的叠加层的透明度:

Then in your Java code you can dynamically set the transparency of your overlay:

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

这篇关于安卓:叠加图片(JPG格式)与透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆