2017-02-20 54 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>