Android 无法获取线性布局的精确高度

Android 无法获取线性布局的精确高度,android,android-widget,Android,Android Widget,我有一个自定义布局的弹出窗口,包含文件项列表。我想根据自定义布局的高度设置弹出窗口的高度。我试过了 布局: <?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"

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

布局:

<?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>

我得到的高度是106,宽度是191。因此,我的弹出窗口仅显示第一个文本视图“first item”(太坏),第二个项目由于高度较低而隐藏。请帮帮我

这可能有助于您创建流行音乐

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\u PARENT
LayoutParams.WRAP\u CONTENT

这显示了全屏宽度的弹出窗口。我想将其显示在特定布局的顶部,然后更改mpopup.showAtLocation(popUpView,Gravity.BOTTOM,0,0);
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;

}
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