Fragment gets no width and no height

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Fragment gets no width and no height



enter image description here



The Dialog that you see is a activity with a Dialog theme. The layout inside it is
a fragment that should match its width and height. It is added programatically using the FragmentTransaction class.


FragmentTransaction



The issue is that the fragment layout gets squished together and looks awful. I have used match_parent in the xml on both the fragments layout and activitys.


match_parent



How do i stop the dialog from being squished together and have a more "natural" size?



ACTIVITY


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myapp.rangevoice2.RoundActivity">

<FrameLayout
android:id="@+id/round_placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

</FrameLayout>
</android.support.constraint.ConstraintLayout>



FRAGMENT


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myapp.rangevoice2.CreateRoundFrag">

<!-- TODO: Update blank fragment layout -->

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<ImageView
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:src="@color/place_autocomplete_prediction_primary_text_highlight"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

<TextView
android:id="@+id/numberOfHoles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:text="@string/number_of_holes"
android:textColor="@color/cast_expanded_controller_background_color"
android:textSize="14sp"
app:layout_constraintBottom_toTopOf="@+id/divider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/radioGroup" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

<RadioButton
android:id="@+id/nineHoles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:text="@string/nine_holes" />

<RadioButton
android:id="@+id/eighteenHoles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/eighteen_holes" />

</RadioGroup>

<TextView
android:id="@+id/coursesTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/courses"
android:textColor="@color/cast_expanded_controller_background_color"
app:layout_constraintBottom_toTopOf="@+id/divider2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />

<Spinner
android:id="@+id/outSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toStartOf="@+id/dash"
app:layout_constraintTop_toBottomOf="@+id/divider" />

<Spinner
android:id="@+id/inSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/outSpinner" />

<ImageView
android:id="@+id/divider2"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:src="@color/place_autocomplete_prediction_primary_text_highlight"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/outSpinner" />

<ImageView
android:id="@+id/dash"
android:layout_width="15dp"
android:layout_height="3dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@color/cast_expanded_controller_background_color"
app:layout_constraintBottom_toBottomOf="@+id/inSpinner"
app:layout_constraintEnd_toStartOf="@+id/inSpinner"
app:layout_constraintTop_toTopOf="@+id/inSpinner" />

<TextView
android:id="@+id/playersTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/players"
android:textColor="@color/cast_expanded_controller_background_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider2" />

</android.support.constraint.ConstraintLayout>







Most of times I faced this issue is when I used a wrong Theme for Dialogs. Put the pointer/cursor over the declared custom style and check if it has "android:windowMinWidthMajor" and "android:windowMinWidthMinor" attributes as explained here: stackoverflow.com/questions/20199118/… Without these parameters the Dialog shrinks itselfs to minimum size if the MATCH_PARENT attribute is used in the main Root of its contained View. Try even to use WRAP_CONTENT in the main contained Root View
– emandt
Aug 12 at 9:13




1 Answer
1



Customizing the height and width of alert dialog android. Following is the code


WindowManager.LayoutParams params = new WindowManager.LayoutParams();

params.copyFrom(alertDialog.getWindow().getAttributes());
params.width = 100;
params.height = 400;
params.x=-190;
params.y=80;
alertDialog.getWindow().setAttributes(params);



Not sure but hope it will work.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard