显示带有全屏图像的对话框仅占屏幕的80%

时间:2015-09-01 15:01:44

标签: android dialog viewgroup layoutparams

我希望全屏显示图像,然后在用户按下时关闭。

我正在使用Dialog,它占据了大约80%的屏幕。我的图像周围有一个白色边框(我的文件系统中没有这个边框)。

如何使此对话框全屏显示?

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        boolean viewedInstructions = sharedPreferences.getBoolean("instructions_viewed", false);
        if (!viewedInstructions) {
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putBoolean("instructions_viewed", true);
            editor.commit();

            final Dialog d = new Dialog(this);
            d.requestWindowFeature(Window.FEATURE_NO_TITLE);
            d.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            d.setContentView(R.layout.instructions_dialog);
            d.findViewById(R.id.tutorial).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    d.dismiss();
                }
            });

            d.show();

布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/dialog_layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:padding="10dp"
    >


    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tutorial"
        android:src="@drawable/dashboard_instructions"/>

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

尝试更改此行

final Dialog d = new Dialog(this);

final Dialog d = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);

答案 1 :(得分:0)

试试这个:

 final Dialog d = new Dialog(this,R.style.MyDialogStyle);

并在styles.xml中定义此样式:

 <!-- Animation for dialog box -->
    <style name="MyDialogStyle"       parent="@android:style/Theme.Translucent.NoTitleBar">
    </style>

您也可以在Manifest中定义它,为活动设置它:

<activity
    android:name="com.example.YourActivity"
    android:theme="@android:style/Theme.Translucent.NoTitleBar">
 </activity>