2017-02-20 70 views
0

我試圖顯示一個ListPopupWindow單擊列表視圖項目。 ListPopupWindow中的項目是可滾動的。但我無法給底部邊緣,它觸及屏幕底部。ListPopupWindow marign底部不工作

private ListPopupWindow getListMenu(Context context, View anchor, String[] options) { 
    Context wrapper = new ContextThemeWrapper(context, R.style.ProfilePicPopUp); 
    ListPopupWindow popupWindow = new ListPopupWindow(wrapper); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, 
      R.layout.listpopup_item, options); 
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
    popupWindow.setAdapter(adapter); 
    popupWindow.setAnchorView(anchor); 
    popupWindow.getAnimationStyle(); 
    popupWindow.setModal(true); 
    popupWindow.setHorizontalOffset((anchor.getWidth()*3)/4); 
    popupWindow.setVerticalOffset(-anchor.getHeight()/4); 

    DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 
    int width = metrics.widthPixels; 
    popupWindow.setWidth((width * 3)/4); // note: don't use pixels, use a dimen resource 


    return popupWindow; 
} 

listpopup_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    fontPath="Lato-Bold.ttf" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/profilepic_option_click_selector" 
    android:ellipsize="marquee" 
    android:gravity="center_vertical" 
    android:paddingBottom="7dp" 
    android:paddingEnd="15dip" 
    android:paddingStart="14dip" 
    android:paddingTop="7dp" 
    android:text="sample" 
    android:textColor="@color/white" /> 
+0

你可以發佈你的'xml'佈局的自定義視圖? –

回答

0

我瀏覽代碼在ListPopupWindow,我包含一個ListView,所以你可以試試這個代碼來設置保證金底部列表視圖。

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) listPopupWindow.getListView() 
      .getLayoutParams(); 

    mlp.setMargins(0, 0, 0, yourMarginBottom); 

如果你想有一個靈活的ListView,您可以創建PopupWindow

+0

謝謝RoShan。它的工作。 – Arunkrishna

0

試試這個。看看填充元素。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="10dip"   
    android:background="@color/colorbg">  
</LinearLayout>