2013-03-18 118 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。

相关问题