2つの異なる画像があり、異なるビューを使用して設定したいのですが、下の画像と一致するように少し重なっています。また、それぞれに異なる設定ができるようにしたいと思いOnClickListener
ます。x
iOSではとの値を使用してビューの位置を設定できることは知っていy
ますが、Androidでこれを行う方法がわかりません。
どうすればこれを行うことができますか?
望ましい結果:
イメージワン
画像2
これらの2つの画像をImageView
'sとして設定し、それらをの中に入れてみてくださいFrameLayout
。そうすれば、好きなように設定できるので、互いに重なり合うことができます。このようにして、両方のプロパティclickable
とonClick
プロパティを別々に設定できます。
<?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
し、アクティビティで各画像のクリックが何をすべきかを決定します。
最初の画像を好きなように配置してから、2番目の画像を使用するためにxmlに配置できます
android:layout_toRightOf="firstImageId"
その後、各onClickを個別に設定できます。