2012-02-27 119 views
0

我需要在我希望用户看到的真实图像顶部覆盖透明图像。这些图像将存储在SD卡上。我看过很多关于这样做的教程,但他们似乎总是缺乏我如何获得显示的两个图像。或者,我只是想念它。总之,这里是我的布局Android动态透明图像覆盖

<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> 

这里是我的代码:

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); 
    } 

我敢肯定我的错误是在我的代码。

编辑1 我已经做了一些测试,它确实显示xml布局是好的。我可以单独显示可见图像,但是当我显示第二张图像(透明图像)时,我所得到的只是一个空白的全黑显示。

要显示第二个图像,我是否第二次调用setImageBitmap()?我开始认为我需要做别的事情。

+0

在Edit1中添加了一些额外的信息 – MrGibbage 2012-02-27 11:08:27

+0

retagged布局和图像到他们特定的标签android-layout和android-images – 2012-02-27 11:13:03

+0

合并标签在我的xml中完全不起作用,app不会启动。我在这里找到答案http://stackoverflow.com/questions/14718028/android-how-to-add-transparent-image-over-another-image – steveh 2014-06-25 02:51:38

回答

1

我想通了。我需要从布局xml中删除android:background =“#FF000000”。