Android的动态透明的图像覆盖 [英] Android Dynamic Transparent Image Overlay

查看:118
本文介绍了Android的动态透明的图像覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有覆盖在我希望用户看到真实的图像的顶部透明的形象。该图像将被存储在SD卡上。我看到的这样很多教程,但他们似乎总是达不到我只是如何让显示两个图像。或者,也许我只是失踪了。总之,这里是我的布局

I need to have a transparent image overlaid on top of the real image I want the user to see. The images will be stored on the SD card. I have seen many tutorials on doing this, but they always seem to fall short of just how do I get the two images displayed. Or maybe I'm just missing it. Anyway, here is my layout

<merge 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/gallerylayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:id="@+id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
  <ImageView
    android:id="@+id/colormap_overlay"
    android:background="#FF000000"      
    android:scaleType="fitXY"
    android:layout_alignTop="@id/visible_image"
    android:layout_alignBottom="@id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
</merge>

和这里是我的code:

and here is my code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ctx = getApplicationContext();
    setContentView(R.layout.imagepage);
    String image_overlay = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/overlay.jpg";
    String visible_image = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/visible.jpg";

    ImageView image = (ImageView)findViewById(R.id.visible_image);
    BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap bm = BitmapFactory.decodeFile(visible_image, options);
    image.setImageBitmap(bm);

    ImageView overlayimage = (ImageView)findViewById(R.id.colormap_overlay);
    Bitmap bm2 = BitmapFactory.decodeFile(image_overlay);
    overlayimage.setAlpha(0);
    overlayimage.setImageBitmap(bm2);
    }

我是pretty肯定我的错误是在我的code。

I am pretty sure my error is in my code.

EDIT1
我做了一些测试,它确实出现了XML布局是确定的。我可以自己显示可见光图像,但当我拿出第二图像(透明图像),我得到的是一个空的,全黑显示。

Edit1 I have done some testing and it does appear that the xml layout is ok. I can show the visible image by itself, but when I show the second image (the transparent image), all I get is an empty, all black display.

要显示在第二图像,我只是叫setImageBitmap()第二次?我开始想我需要做些别的事情。

To show the second image, do I just call setImageBitmap() a second time? I am beginning to think I need to do something else.

推荐答案

我想通了。我需要删除的android:从布局XML背景=#FF000000

I figured it out. I needed to remove the android:background="#FF000000" from the layout xml.

这篇关于Android的动态透明的图像覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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