Android Popupwindow全屏显示

最近做项目中需要popupwindow全屏展示,这时需要设置参数让它全屏,具体代码如下:

private void init(){
      area=(RelativeLayout)findViewById(R.id.area);
}
 
private void createFunctionPopupWindow() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.interestscreen_layout, null, false);
        PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popupWindow.setClippingEnabled(false);
        popupWindow.showAtLocation(area, Gravity.TOP,0,0);
    }

2.MainActivity的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/area"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/otherapp_bg">
  
    <Button
        android:id="@+id/btn_open"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Open"
        android:layout_centerInParent="true"
        />
    <Button
        android:id="@+id/btn_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="背光"
        android:layout_toRightOf="@id/btn_open"
        android:layout_alignTop="@id/btn_open"
        android:layout_marginRight="200px"
        />
</RelativeLayout>

3.interestscreen_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/interestscreen_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/bg_17"
        android:scaleType="fitCenter" />
</RelativeLayout>

你可能感兴趣的:(android)