ScrollView causes scrolling when adding margin/padding even if the content don't need extra space

Viewed 356

I'm working on this layout containg a scroll view which contains a linear vertical layout that wraps an image on top and a couple of text views. Even if no extra space is needed to show the content the scrolling happens anyway. Here is the xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/ToolbarLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ShowProfileActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="3">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/profile_image_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/user_image"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:contentDescription="@string/user_image"
                android:scaleType="centerCrop"
                android:src="@drawable/user"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

        <LinearLayout
            android:id="@+id/user_info_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:orientation="vertical">

            <TextView
                android:id="@+id/user_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="@string/full_name"
                android:textColor="#000000"
                android:textSize="24sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2">

                <TextView
                    android:id="@+id/datebirth"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:autofillHints=""
                    android:text="@string/birthdate"
                    android:textColor="#000000"
                    android:textSize="18sp" />

                <TextView
                    android:id="@+id/gender"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:autofillHints=""
                    android:text="@string/gender"
                    android:textColor="#000000"
                    android:textSize="18sp" />

            </LinearLayout>

            <TextView
                android:id="@+id/user_nickname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/nickname"
                android:padding="10dp"
                android:text="@string/nickname"
                android:textColor="#000000"
                android:textSize="18sp"
                android:textStyle="italic" />

            <TextView
                android:id="@+id/user_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/email_address"
                android:inputType="textEmailAddress"
                android:padding="10dp"
                android:text="@string/email_address"
                android:textAllCaps="true"
                android:textColor="#000000"
                android:textSize="18sp"
                android:textStyle="italic"
                tools:ignore="TextViewEdits" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="2">

                <TextView
                    android:id="@+id/user_state"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:hint="@string/state"
                    android:text="@string/state"
                    android:textColor="#000000"
                    android:textSize="18sp"
                    android:textStyle="italic" />

                <TextView
                    android:id="@+id/user_city"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:hint="@string/city"
                    android:text="@string/city"
                    android:textColor="#000000"
                    android:textSize="18sp"
                    android:textStyle="italic" />
            </LinearLayout>

            <TextView
                android:id="@+id/user_postal_code"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/postal_code"
                android:padding="10dp"
                android:text="@string/postal_code"
                android:textColor="#000000"
                android:textSize="18sp"
                android:textStyle="italic" />

            <TextView
                android:id="@+id/user_address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/address"
                android:padding="10dp"
                android:text="@string/address"
                android:textColor="#000000"
                android:textSize="18sp"
                android:textStyle="italic" />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

The following is an image showing the problem. How is possible to prevent this? I've already tried some attributes for the ScrollView like fillViewport to true but that doesn't help.

enter image description here

0 Answers
Related