0

So whenever I click a button in order to show my dialog box, it displays the dialog box like this, its too narrow.Sorry new account image of un-intended results here.please help me fix this, I want it to show like in the designer here ( again sorry for external links).

Here is the xml code for the dialog fragment:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<TextView
    android:layout_width="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_marginTop="20dp"
    tools:text="Enter new member details"
    android:textSize="20sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/instructions_text"
    android:layout_height="wrap_content"/>

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="0dp"
    android:id="@+id/name_layout"
    app:layout_constraintStart_toStartOf="parent"
    android:layout_marginTop="20dp"
    android:hint="@string/name"
    app:layout_constraintTop_toBottomOf="@+id/instructions_text"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_height="wrap_content">
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:id="@+id/name"
        android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="0dp"
    android:id="@+id/surname_layout"
    app:layout_constraintStart_toStartOf="parent"
    android:hint="@string/surname"
    android:layout_marginTop="20dp"
    app:layout_constraintTop_toBottomOf="@+id/name_layout"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_height="wrap_content">
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:id="@+id/surname"
        android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="0dp"
    android:id="@+id/dob_layout"
    app:layout_constraintStart_toStartOf="parent"
    android:hint="@string/birth_date"
    android:layout_marginTop="20dp"
    app:layout_constraintTop_toBottomOf="@+id/surname_layout"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_height="wrap_content">
    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:id="@+id/date_of_birth"
        android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

<Button
    android:layout_width="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    android:id="@+id/add_button"
    android:layout_marginTop="10dp"
    android:text="@string/add"
    app:layout_constraintTop_toBottomOf="@id/dob_layout"
    android:layout_height="wrap_content"/>

<Button
    android:layout_width="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    android:id="@+id/cancel_button"
    android:layout_marginTop="10dp"
    android:text="@string/cancel"
    app:layout_constraintTop_toBottomOf="@id/dob_layout"
    android:layout_height="wrap_content"/>

</androidx.constraintlayout.widget.ConstraintLayout>

I found a somewhat similar post from 8 years ago, a "solution was to set min-width and min-height , but I don't want to hard-code values in for such kind of an issue, I did try that and it worked but it looked weird on another device I tested. Isn't there a more official or better solution to that? Thanks for any input. Oh also here is my code for the dialog box inflator:

class NewMemberDialogue: DialogFragment() {
private lateinit var binding: DialogLayoutBinding
override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View {
    binding = DialogLayoutBinding.inflate(layoutInflater,container,false)
    binding.cancelButton.setOnClickListener { dismiss() }
    return binding.root
}

}

1 Answers1

0

"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."

Custom dialog too small

R Millaci
  • 71
  • 3