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:
我有没有灰色封面的图片,想添加此封面,但步骤不同。
有人可以给我提示如何做到这一点吗?
您可以使用小部件简单地做到这一点:
框架布局是将一个视图覆盖在另一个视图之上的一般机制:
<?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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)