Custom dialog too small

我的未来我决定 提交于 2019-11-28 10:52:07

Change your dialog dimension on runtime:

yourDialog.show();
yourDialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);

You can do that for both dimension, in my example i only changed the width. Hope it helps!

EDIT

I forgot to mention where i took width:

DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;

EDIT 2

Try this code:

Dialog yourDialog = dialogFragment.getDialog();
yourDialog.getWindow().setLayout((6 * width)/7, (4 * height)/5);

Setting android:minWidth and android:minHeight in the custom layout does the trick for me.

put below line in onCreate

setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);

original answer

Narendra
<style name="full_screen_dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:minWidth" type="dimen">600dp</item>
</style>

Use this in style.xml file and use this style in dialog class

The right solution is to override the onCreateDialog method rather than onCreateView, and create your dialog with a AlertDialog.Builder, as explained in the doc: http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog

Dialogs are sized by their content. You can add padding and margins on the outer layout to consume more space, but that will not redistribute the views inside.

Try this

For setting dialog width and height as per device screen size

    Display display;
    int DisplayWidth, DisplayHeight, DialogWidth, DialogHeight;
    Dialog dialog;

display =((WindowManager)activity_context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        DisplayWidth = display.getWidth();
        DisplayHeight = display.getHeight();

        if(DisplayHeight > DisplayWidth)
        {
            DialogWidth = (6 * DisplayWidth) / 7 ;
            DialogHeight = (4 * DisplayHeight) / 5 ;
        }
        else
        {
            DialogWidth = (6 * DisplayWidth) / 9 ;
            DialogHeight = (4 * DisplayHeight) / 5 ;
        }

        dialog = new Dialog(activity_context);

          // Set your dialog width and height dynamically as per your screen.

        Window window = dialog.getWindow();
        window.setLayout(DialogWidth,DialogHeight);
        window.setGravity(Gravity.CENTER);

        dialog.show();

try to set android:layout_height to some value for base LinearLayout

for example

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"

<!-- right here -->
    android:layout_height="100dp"

android:background="@color/white"
android:orientation="vertical" >

Add android:minWidth / android:minHeight to your root view. See example below:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="300dp"
android:minHeight="500dp">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!