I Have a Dialog with a Custom layout in my layouts Folder, which Wraps its Content. If I pu tin a large Text into one of the TextFields, the Buttons on the Bottom dissapear. The Text itself is scrollable and everything else works just fine. I want the Buttons to stick to the Bottom of the Dialog and not disappear if the text is Too Large. Dialog without TextInput, Dialog with large Text. Icannot post Pictures directly, therefore i just included Links.
I have already tried to change the Layout so the Buttons stick to the Bottom of the Layout instead of the TextView above them. Setting a fixed size isnt really an Option.
Layout of the Dialog Layout:
<?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:background="@drawable/bg_layout_rounded_16">
<EditText
android:id="@+id/dialog_resource_title"
style="@style/myEditTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:hint="@string/general_title_hint"
android:inputType="textMultiLine"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/dialog_resource_description"
style="@style/myEditTextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:hint="@string/general_description_hint"
android:inputType="textMultiLine"
app:layout_constraintBottom_toTopOf="@+id/dialog_resource_cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dialog_resource_title" />
<Button
android:id="@+id/dialog_resource_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="8dp"
android:paddingBottom="8dp"
android:text="@string/general_cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/dialog_resource_middle_line"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/dialog_resource_save"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/general_save"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/dialog_resource_middle_line" />
<android.support.constraint.Guideline
android:id="@+id/dialog_resource_middle_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
</android.support.constraint.ConstraintLayout>
Initialisation of the Dialog:
resourceDialog = new Dialog(context);
View v = LayoutInflater.from(context).inflate(R.layout.dialog_resource, null);
this.resourceDialogTitle = v.findViewById(R.id.dialog_resource_title);
this.resourceDialogDescription = v.findViewById(R.id.dialog_resource_description);
this.resourceDialogCancel = v.findViewById(R.id.dialog_resource_cancel);
this.resourceDialogSave = v.findViewById(R.id.dialog_resource_save);
resourceDialog.setContentView(v);
// Set Color of Root View (Otherwise white Background in the Corners)
resourceDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
// Getting the Display Metrics to set Size of Dialog
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
// Setting the Size
resourceDialog.getWindow().setLayout((width - 128), ViewGroup.LayoutParams.WRAP_CONTENT);
resourceDialog.setCanceledOnTouchOutside(false);
Put the buttons incide a linear layout and use a constraint option to constrain it to the bottom of the screen. For example
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<Button />
<Button />
</LinearLayout>
--Edit-- I tried this and worked for me
<?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.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:paddingBottom="120dp"
android:scrollbars="horizontal"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/appBarLayout"
android:layout_marginLeft="10dp"
android:layout_marginTop="14dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/address"
android:textColor="@color/black_1"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="4dp"
android:textColor="@android:color/white" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="4dp"
android:textColor="@android:color/white" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>