Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在特定视图上方显示弹出窗口_Java_Android_Popupwindow - Fatal编程技术网

Java 在特定视图上方显示弹出窗口

Java 在特定视图上方显示弹出窗口,java,android,popupwindow,Java,Android,Popupwindow,我试图展示一个以上的相对布局 popupWindow.showAtLocation(layout, Gravity.BOTTOM |Gravity.CENTER, 0, layout); 其中布局是相对布局。但它仅显示在底部,而不是相对布局的上方。我查过了,但没用 这是我的弹出窗口布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas

我试图展示一个以上的相对布局

 popupWindow.showAtLocation(layout,  Gravity.BOTTOM
            |Gravity.CENTER, 0, layout);
其中布局是相对布局。但它仅显示在底部,而不是相对布局的上方。我查过了,但没用

这是我的弹出窗口布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:background="@drawable/nearbyplace_bg"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">


        <TextView
            android:id="@+id/txt_school"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_weight="0.8"
            android:text="@string/school"
            android:textSize="17dp" />

        <CheckBox
            android:id="@+id/cb_school"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.2" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">


        <TextView
            android:id="@+id/txt_college"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_weight="0.8"
            android:text="@string/college"
            android:textSize="17dp" />

        <CheckBox
            android:id="@+id/cb_college"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.2" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">


        <TextView
            android:id="@+id/txt_hospital"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_weight="0.8"
            android:text="@string/hospital"
            android:textSize="17dp" />

        <CheckBox
            android:id="@+id/cb_hospital"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.2" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/grey" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">


        <TextView
            android:id="@+id/txt_shoppingmall"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_weight="0.8"
            android:text="@string/shoppingmall"
            android:textSize="17dp" />

        <CheckBox
            android:id="@+id/cb_shoppingmall"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.2" />
    </LinearLayout>

</LinearLayout>

我的主要布局

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/img_static_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/linearLayout1"
            android:layout_marginTop="2dp"
            android:scaleType="centerCrop" />

        <fragment
            android:id="@+id/map"
            class="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/linearLayout1" />

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:orientation="horizontal">

            <!-- <RelativeLayout
                 android:id="@+id/rl_get_nearby"
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
                 android:layout_weight="0.99"
                 android:background="@color/lightGrey">

                 <TextView
                     android:id="@+id/tv_neighbour"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_centerHorizontal="true"
                     android:layout_centerVertical="true"
                     android:drawableLeft="@drawable/ic_view_map"
                     android:gravity="center"
                     android:text=" View On Map"
                     android:textSize="14sp" />
             </RelativeLayout>

             <View
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
                 android:layout_weight="0.02"
                 android:background="@color/grey" />-->

            <RelativeLayout
                android:id="@+id/layout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.99"
                android:background="@color/lightGrey">

                <TextView

                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:drawableLeft="@drawable/ic_area"
                    android:drawablePadding="10dp"
                    android:gravity="center_vertical"
                    android:text="Soham"
                    android:textSize="20sp" />
            </RelativeLayout>
        </LinearLayout>

    </RelativeLayout>

您可以使用此方法执行此操作

private void displayPopupWindow(View anchorView) {
        PopupWindow popup = new PopupWindow(Pdf.this);
        View layout = getLayoutInflater().inflate(R.layout.popup_content, null);
        popup.setContentView(layout);
        // Set content width and height
        popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        // Closes the popup window when touch outside of it - when looses focus
        popup.setOutsideTouchable(true);
        popup.setFocusable(true);
        popup.setBackgroundDrawable(new BitmapDrawable());
        // Show anchored to button
        popup.showAtLocation(anchorView, Gravity.BOTTOM, 0,
                anchorView.getBottom() - 60);

        popup.showAsDropDown(anchorView);
    }

您的最后一个参数不应该是布局,它应该是y偏移量。@jimmy0251 y偏移量应该是多少。?它是弹出窗口与定位视图的y位置偏移量。不工作,位于窗口顶部我测试每个子线性布局的工作精细度我已添加了主布局。我正在显示弹出窗口单击id布局我已更改答案更改重力。底部我已尝试过,它显示在底部,而不是我想要的布局上方。):