2013-03-18 123 views
3

我有兩個不同的圖像,並希望使用不同的視圖設置它們,但稍微重疊以匹配下面的圖像。我也希望能夠爲他們每個人設置不同的OnClickListener。我知道在iOS中,我可以使用xy值設置視圖位置,但我不確定如何在Android中執行此操作。如何在Android中使用位置設置這兩個不同的圖像?

我該如何去做這件事?

期望的結果:

enter image description here

圖像的一個

enter image description here

圖像中的兩個

enter image description here

+0

我會嘗試在相對layout_alignofright中,但不是完美的工作 – 2013-03-18 17:40:08

+0

試圖添加一個負邊距? – njzk2 2013-03-18 17:40:49

回答

2

嘗試將這兩個圖像設置爲ImageView's並將它們放入FrameLayout中。這樣你就可以根據需要設置它們,因此它們可以相互重疊。這樣,你可以單獨爲他們兩個設置clickableonClick屬性:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/iFirstImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@drawable/sort_image_1" 
    android:clickable="true" 
    android:onClick="setFirstImageClick" 
    android:src="@drawable/sort_image_1" /> 

<ImageView 
    android:id="@+id/iSecondImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@drawable/sort_image_2" 
    android:clickable="true" 
    android:onClick="setSecondImageClick" 
    android:src="@drawable/sort_image_2" /> 

,創造方法和setSecondImageClick在您的活動來決定每個圖像點擊應該做的事情。

+0

如果圖像大小不同,我如何爲不同的屏幕分辨率設置兩個圖像 – Mahesh 2013-06-14 06:44:53

0

可以放置在F然後在xml中爲第二張圖片使用

android:layout_toRightOf="firstImageId" 

然後,您可以分別設置每個onClick。

相關問題