我试图在点击列表视图项目时显示ListPopupWindow。 ListPopupWindow中的项目是可滚动的。但我无法给它底部边缘,它触及屏幕的底部。
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 :(得分: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>
答案 1 :(得分:0)
我在ListPopupWindow中浏览代码,我包含一个列表视图,因此您可以尝试使用此代码为listview设置边距底部。
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) listPopupWindow.getListView()
.getLayoutParams();
mlp.setMargins(0, 0, 0, yourMarginBottom);
如果您想要灵活ListView
,可以创建PopupWindow
的自定义视图