我有一个图片(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