Reputation: 161
I have a registration screen in my app but it looks bad on phones with a small screen. The main problem is I want to restrict the ScrollView boundaries to scroll the form on the picture (now it is not scrollable on the left picture). I want this form to be never able to get higher than the toolbar or lower than the button. Everything that doesn't fit the boundaries should be cut.
The layout itself:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/action_bar_toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/action_bar_background"
android:minHeight="40dp"
android:theme="@style/toolbar_theme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:titleTextColor="@color/tool_bar_text_color">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/action_bar_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="User Registration"
android:textColor="@color/tool_bar_text_color"
android:textSize="@dimen/action_bar_title_text_size" />
</androidx.appcompat.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbarSize="100dp"
app:layout_constraintBottom_toTopOf="@+id/submit_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/action_bar_toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/first_name_layout"
style="@style/MaterialTextInputLayout"
android:layout_width="@dimen/text_field_width"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/wizard_sign_up_first_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/action_bar_toolbar">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>
<!-- 6 more similar elements -->
</LinearLayout>
</ScrollView>
<com.google.android.material.button.MaterialButton
android:id="@+id/submit_btn"
android:layout_width="@dimen/default_button_width"
android:layout_height="@dimen/default_button_height"
android:layout_marginBottom="10dp"
android:elevation="2dp"
android:text="@string/wizard_sign_up_submit"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Upvotes: 0
Views: 411
Reputation: 75788
You should add ScrollView android:layout_height="0dp"
.
Using 0dp, which is the equivalent of "MATCH_CONSTRAINT"
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:scrollbarSize="100dp"
app:layout_constraintBottom_toTopOf="@+id/submit_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/action_bar_toolbar">
Upvotes: 1