私はこれに本当に苦労しており、何をしても、ポップアップウィンドウが表示されたくない場所に表示され続けています。クリック/タッチした場所に表示するか、画像をタップしたときにタッチした場所に少しオフセットを付けたいです。
これは、画像がタップされたときにxmlで設定したメソッドです:
public void loadPopUp(View v) {
popUp.showAtLocation((View) v.getParent().getParent(),
Gravity.NO_GRAVITY, 0, 0);
popUp.update(v.getLeft(), "No clue what to put here", 300, 80);
}
2 よくわからないポップアップ ウィンドウに関すること。showAtLocation の最初のパラメーターをルート ビューにする必要があるので、ビューが内部にあるレイアウトだけでなく、レイアウト全体を網羅する必要がありますか?
また、y座標を機能させることができないため、「ここに何を入れればよいかわかりません」。私の x (v.getLeft()) は問題ありません。アプリが左右に動かないためです。ユーザーが画像をタップした場所を取得するのに苦労しているのは上下だけです。
XML :
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="small" >
<LinearLayout
android:id="@+id/godOverview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/godItemRowOneLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/godItem1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:contentDescription="@string/god_recommended_item_1"
android:onClick="loadPopUp"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/godItem2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:contentDescription="@string/god_recommended_item_2"
android:onClick="loadPopUp"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/godItem3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/god_recommended_item_3"
android:onClick="loadPopUp"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</ScrollView>