0

我有一个包含文件项列表的自定义布局的弹出窗口。我想根据自定义布局的高度设置弹出窗口的高度。我试过了

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fileName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="#303030"
    android:orientation="vertical" >
   <TextView
            android:id="@+id/newfile"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:text="first item"
            android:textColor="@color/white"
            android:drawableLeft="@drawable/zw_new"
            android:drawablePadding="5dp"
            android:padding="10dp"
            android:textSize="20sp" />
   <View style="@style/hrView" />
   <TextView
            android:id="@+id/rename"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            android:text="second item"
            android:textColor="@color/white"
            android:drawableLeft="@drawable/zw_rename"
            android:drawablePadding="5dp"
            android:padding="10dp"
            android:textSize="20sp" />
</LinearLayout>

样式.xml

 <style name="hrView">
          <item name="android:layout_width">fill_parent</item>
          <item name="android:layout_height">1dp</item>
          <item name="android:background">#4f4f4f</item>
    </style>

代码:

public static PopupWindow fileMenu= null; 
    public void showfileMenu(){         
        View fileMenuView=null;

            fileMenuView =  getLayoutInflater().inflate (R.layout.zw_filemenu, null);
        fileMenuView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

        int h = fileMenuView.getMeasuredHeight();
        int w = fileMenuView.getMeasuredWidth();
            fileMenu=showPopup(fileMenuView,w,h);
        }

PopupWindow pw=null;
public PopupWindow showPopup(View view,int w,int h) {
    pw = new PopupWindow(EditorActivity.getActivity());
    pw.setWidth(w);
    pw.setHeight(h);
    pw.setTouchable(true);
    pw.setFocusable(true);
    pw.setOutsideTouchable(true);
    pw.setTouchInterceptor(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                pw.dismiss();

                return true;
            }

            return false;
        }
    });
    pw.setOutsideTouchable(false);
    pw.setContentView(view);
    return pw;

}

我的高度为 106,宽度为 191。因此,我的弹出窗口仅显示第一个文本视图“第一项”(太坏了),第二项由于高度较小而被隐藏。请帮我。

4

1 回答 1

0

这可能会帮助您创建流行音乐

private PopupWindow mpopup;

View popUpView = getLayoutInflater().inflate(R.layout.yourxml, null); // inflating popup layout
        mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT, true); // Creation of popup
        mpopup.setAnimationStyle(R.style.DialogAnimation);
        mpopup.showAtLocation(popUpView, Gravity.BOTTOM, 0, 0); // Displaying

我在这里给 LayoutParams.FILL_PARENTLayoutParams.WRAP_CONTENT

于 2013-04-16T13:39:12.400 回答