TootsieRockNRoll
TootsieRockNRoll

Reputation: 3288

android android.support.v4.app.DialogFragment set size

I have a android.support.v4.app.DialogFragment, when it is shown, the height is max, but the widht is just wraping the content, I need to set a custom height,

I already tried this:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
getDialog().getWindow().setLayout(2000, 2000);  
super.onViewCreated(view, savedInstanceState);
}

but the result is always the same

EDIT1

here is the xml layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:minHeight="10000dp"
    android:minWidth="10000dp" >

.......content
</RelativeLayout>

EDIT2

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.marche_charts, container, false);

        WindowManager.LayoutParams wmlp = getDialog().getWindow().getAttributes();
        wmlp.gravity = Gravity.CENTER;
        wmlp.height = 2000;
        wmlp.width = 2000;
        getDialog().getWindow().setAttributes(wmlp);
        return view;
    }

Upvotes: 0

Views: 1579

Answers (3)

Maciej Boguta
Maciej Boguta

Reputation: 1374

you need to override onActivityCreated() method and put this getDialog().getWindow().setLayout(2000, 2000); in there

Upvotes: 1

Eugene Popovich
Eugene Popovich

Reputation: 3473

Use setMinWidth when you are creating the view (onCreateView method) for the DialogFragment. For example

final DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

view.setMinimumWidth((int) (Math.min(displaymetrics.widthPixels,
        displaymetrics.heightPixels) * 0.9f));

Upvotes: 0

Maciej Boguta
Maciej Boguta

Reputation: 1374

put match_parent on both width and height inside of your xml layout.

Upvotes: 0

Related Questions