2012-02-27 190 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」。