我想显示一个宽度应该适合平板电脑屏幕大小的对话框,谁能告诉我怎么做,我尝试设置宽度,但没有成功。
代码如下:
final Dialog nagDialog = new Dialog(MainActivity.this);
Window window = nagDialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.width= WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(wlp);
getWindow().setGravity(Gravity.BOTTOM);
nagDialog.setContentView(R.layout.popuplayout);
nagDialog.show();
popuplayout.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"
android:background="@color/transparent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="84dp"
android:layout_marginTop="59dp"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img"
android:layout_marginLeft="130dp"
android:layout_toRightOf="@+id/img"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img"
android:layout_marginLeft="130dp"
android:layout_toRightOf="@+id/img"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/img"
android:layout_marginLeft="347dp"
android:layout_toRightOf="@+id/img"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageButton5"
android:layout_marginLeft="163dp"
android:layout_toRightOf="@+id/imageButton5"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageButton4"
android:layout_marginLeft="110dp"
android:layout_toRightOf="@+id/imageButton4"
android:src="@drawable/ic_launcher" />
</RelativeLayout>