1

正確な位置ではなく、ボタンの下にポップアップを表示するにはどうすればよいですか? 現在、これはポップアップが表示される場所を設定する私のコードです。

popUpFollowUsername.showAtLocation(findViewById(R.id.dashboardRelative), Gravity.TOP, 100, 280);

このボタンであるボタンのすぐ下に表示したい

<Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/post"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:textSize="20sp"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:background="@drawable/dashboard_post"
        android:id="@+id/btnPost"/>

複数の Android フォンを使用していますが、ポップアップはすべてのフォンで異なる場所に表示されます。投稿ボタンのすぐ下に常に表示されるようにするにはどうすればよいですか?

4

1 に答える 1

0

View.getLocationOnScreen()および/またはを使用View.getLocationInWindow()して、画面上のビューの位置を取得できるようにします。この情報があれば、ポップアップをボタンの近くに配置するのは簡単です。

基本的にそのようなものを使用します:(テストされていません)

Button btn = get(); // maybe with findViewById
btn.setOnClickListener(new OnClickListener() {
    void onClick(View v) {
        int[] pos = new int[2];
        v.getLocationInWindow(pos);
        int x = pos[0];
        int y = pos[1] + v.getHeight();
        // show popup at the given x,y position
    }
});
于 2013-07-20T22:27:03.340 に答える