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

Displaying a Dialog with a full screen image only takes up 80% of the screen

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

我正在使用对话框,它占据了大约 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>

试试这个:

 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:

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

尝试更改此行

final Dialog d = new Dialog(this);

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