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

前端之家收集整理的这篇文章主要介绍了Android:用透明度覆盖图片(jpg)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个图片(jpg),我想在屏幕上显示.
此外,图片应部分覆盖透明效果.
透明盖应该是动态的.例如每一天都会显示更多的图片.
这里有一张照片来显示我的意思:

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

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

解决方法

您可以使用小部件:

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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content">
  5. <ImageView
  6. android:id="@+id/image"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:src="@drawable/my_image"/>
  10. <View
  11. android:id="@+id/overlay"
  12. android:layout_width="fill_parent"
  13. android:layout_height="fill_parent"/>
  14. </FrameLayout>

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

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

猜你在找的Android相关文章