3

2つの異なる画像があり、異なるビューを使用して設定したいのですが、下の画像と一致するように少し重なっています。また、それぞれに異なる設定ができるようにしたいと思いOnClickListenerます。xiOSではとの値を使用してビューの位置を設定できることは知っていyますが、Androidでこれを行う方法がわかりません。

どうすればこれを行うことができますか?

望ましい結果:

ここに画像の説明を入力してください

イメージワン

ここに画像の説明を入力してください

画像2

ここに画像の説明を入力してください

4

2 に答える 2

2

これらの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" />

そして、メソッドsetFirstImageClickを作成setSecondImageClickし、アクティビティで各画像のクリックが何をすべきかを決定します。

于 2013-03-18T17:21:18.493 に答える
0

最初の画像を好きなように配置してから、2番目の画像を使用するためにxmlに配置できます

android:layout_toRightOf="firstImageId"

その後、各onClickを個別に設定できます。

于 2013-03-18T17:15:16.090 に答える