2012-03-22 10 views
2

ListViewアイテムをクリックしたときにPopupWindowを使用していくつかのサブカテゴリを表示しています。 ListView行(カテゴリ)とPopupWindow(カテゴリ)に同じレイアウトを使用しています。PopupWindowの幅/スタイルの問題

私の問題は、私のPopupWindowの幅を私の行項目ビューの幅に設定していますが、それが表示されているときに、少し狭く、何らかの境界があります。 I下のスクリーンショットで

がSEにListViewコントロールの上にPopupWindowを置く違い

は、なぜそれが小さいのですか?この境界線を削除するにはどうしたらいいですか?

enter image description here

listView.setOnItemClickListener(...)

listView.setOnItemClickListener(new OnItemClickListener() { 

    @Override 
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {   

      showPopup(HomeActivity.this, layout_base, v, position); 
     } 
    } 
}); 

showPopup(...)

public void showPopup(Context context, View parent, View view, int position){ 

    /* 
    * Compute popup position and size 
    */ 

    int[] itemPosition = new int[2]; 
    view.getLocationOnScreen(itemPosition); 

    int item_width = view.getWidth(); 
    int item_height = view.getHeight(); 

    int nChildren = GlobalVars.menuItemArray[position].children.size(); 

    int popup_height = item_height * nChildren; 

    /* 
    * Build the view 
    */ 

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    LinearLayout popupContainer = new LinearLayout(context); 
    popupContainer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    popupContainer.setOrientation(LinearLayout.VERTICAL); 

    LayoutParams params; 

    params = new LayoutParams(item_width, item_height); 
    popupContainer.setOrientation(LinearLayout.VERTICAL); 

    for(int i=0; i<nChildren; i++){ 

     RelativeLayout menu_row = (RelativeLayout) inflater.inflate(R.layout.menu_row, null);   

     popupContainer.addView(menu_row, params); 
    } 

    mPopup.setContentView(popupContainer); 
    mPopup.setHeight(popup_height); 
    mPopup.setWidth(item_width); 

    mPopup.showAtLocation(parent, Gravity.TOP|Gravity.LEFT, 0, 0);   

} 

答えて

7

私はPopupWindowの背景を削除する必要がありました使用:

mPopup.setBackgroundDrawable(new BitmapDrawable()); 
+2

パラメータとして「null」を使用するだけで、メモリを節約できます。 – manmal

+0

私はこれを複数回upvoteできますことを望みます。 Androidには癖やバグがたくさんあります。実際のコーディングよりもAPIとの戦いに多くの時間を費やしました。 –

+1

@manmal私はそれをnullに設定すると、PopupWindowは私がそれをクリックしたときに閉じることができなくなります。理由は分かりません。 (誰かがこの問題に遭遇した場合) –