3

ポップアップを表示する必要があります。やったのですが、このポップアップの位置を設定できません。友達ラベルの下にポップアップを設定する必要があります。

ここに画像の説明を入力.

コード:

_spinner = (Spinner) view.findViewById(R.id.group_spinner);
_groupAdaptor = new ArrayAdapter(getActivity(), 
                android.R.layout.simple_spinner_dropdown_item, _itemGroupList);
_spinner.setAdapter(_groupAdaptor);
_spinner.setOnItemSelectedListener(this);

クリックすると、次のようなメソッドを呼び出しています。

_spinner.performClick();
4

3 に答える 3

0

この私の作業コードを使用してください..

Rect r = locateView(v);    
final PopupWindow popup = new PopupWindow(getActivity());
            popup.setAnimationStyle(R.style.animation);
            popup.setContentView(layout);
            popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
            popup.setWidth(getActivity().getWindowManager().getDefaultDisplay().getWidth() / 2);
            popup.setFocusable(true);
            popup.setBackgroundDrawable(new BitmapDrawable());
            popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, r.right, r.bottom);


public static Rect locateView(View v) {
        int[] loc_int = new int[2];
        if (v == null)
            return null;
        try {
            v.getLocationOnScreen(loc_int);
        } catch (NullPointerException npe) {
            return null;
        }
        Rect location = new Rect();
        location.left = loc_int[0];
        location.top = loc_int[1];
        location.right = loc_int[0] + v.getWidth();
        location.bottom = loc_int[1] + v.getHeight();
        return location;
    }
于 2013-10-03T12:40:36.327 に答える
0

レイアウトを修正することで問題を解決しました。ばかげた間違いをしていました。Spinner ビューが適切に配置されていませんでした。

  <TextView
                android:id="@+id/group_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="@string/label_friends"
                android:textColor="@android:color/white" />

            <ImageView
                android:id="@+id/dropListImageview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/group_text"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="4dip"
                android:background="@drawable/droplist" />

            <Spinner
                android:id="@+id/group_spinner"
                android:layout_width="150dip"
                android:layout_height="20dip"
                android:layout_centerHorizontal="true"
                android:layout_below="@+id/group_text"
                android:visibility="invisible"
               />
于 2013-10-03T12:48:45.053 に答える
-1

私も自分のアプリケーションで同じ問題に直面し、spinier を使用して解決策を見つけました。あなたがしなければならないことは、友達をクリックしてドロップダウンリストを表示し、そのメニューにオプションを表示するだけです。それはあなたを助けるでしょう。

于 2013-10-03T12:40:47.370 に答える