I'm building a DialogFragment used to display some filters an user can apply. This is the layout of the custom view I want to build:
<?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">
<android.support.constraint.Guideline
android:id="@+id/guideline_vertical_centered"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<CheckBox
android:id="@+id/checkbox_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginStart="100dp"
android:layout_marginTop="16dp"
android:checked="true"
app:layout_constraintEnd_toStartOf="@+id/search_by_title"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/search_by_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="22dp"
android:text="Titolo"
app:layout_constraintStart_toEndOf="@+id/checkbox_title"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkbox_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:checked="true"
app:layout_constraintStart_toEndOf="@+id/guideline_vertical_centered"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="22dp"
android:text="Autore"
app:layout_constraintStart_toEndOf="@+id/checkbox_author"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkbox_publisher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:checked="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline7" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="6dp"
android:text="Editore"
app:layout_constraintStart_toEndOf="@+id/checkbox_publisher"
app:layout_constraintTop_toTopOf="@+id/guideline7" />
<CheckBox
android:id="@+id/checkbox_tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:checked="true"
app:layout_constraintStart_toEndOf="@+id/guideline_vertical_centered"
app:layout_constraintTop_toBottomOf="@+id/guideline7" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="6dp"
android:text="Tags"
app:layout_constraintStart_toEndOf="@+id/checkbox_tags"
app:layout_constraintTop_toTopOf="@+id/guideline7" />
<android.support.constraint.Guideline
android:id="@+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="64dp"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Which on the preview looks like this:
But, since I want the dialog to not fill the entire screen, I set its size this way:
Window window = getDialog().getWindow();
Point size = new Point();
Display display = window.getWindowManager().getDefaultDisplay();
display.getSize(size);
window.setLayout((int) (size.x * 0.75), WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
super.onResume();
Which results in this:
So my question is: how can I use constraint layout and then make its constraints scale to the dimension of the window?
I know that for the elements I added a constraint layout is unnecessary, but I plan on adding much more elements with a non-fixed layout.
Thank you all in advance!