2013-10-03 55 views
7

我必須顯示彈出窗口。我已經做到了,但我無法設置這個彈出窗口的位置。 我必須在朋友標籤的下方設置彈出。顯示設置彈出的位置?

enter image description here

代碼:

_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(); 
+0

你能發佈你的佈局代碼嗎? – GrIsHu

+0

你可以使用自定義對話框,或者你想在微調器中使用它嗎? –

回答

1

我已經通過佈局中的某些更正解決了我的問題。 我在做一個愚蠢的錯誤,微調視圖沒有正確對齊。

<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" 
       /> 
+0

這裏有什麼確切的解決方案? –

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; 
    } 
5

我也面臨着同樣的問題我的應用程序,並通過使用spinier找到了解決方案。你必須做的只是點擊朋友的用戶spinier下拉列表並在該菜單中顯示你的選項。它會幫助你。

+2

爲什麼複製user2119025的粘貼回答? – GrIsHu

+0

標記此答案@GrIsHu – Sameer

+1

其實它是我的錯誤,那是我自己的ID,它是由錯誤創建的,我將從該ID中刪除該答案。 –