Search code examples
androidandroid-studioandroid-layoutscrollview

Android ScrollView: Bottom Button not showing


The problem is I want to make my registration activity scrollable, but whenever I launch the app,I can scroll but I cannot view the button below. I have tried putting alignParentTop = true and it focuses on the first edittext.

Here is my code:

 <LinearLayout>

      <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical">
            <!-- Add CONi icon here -->

            <EditText
                android:id="@+id/editlastname"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20sp"
                android:ems="10"
                android:hint="@string/lastname"
                android:inputType="textPersonName" />

        </LinearLayout>

    </ScrollView>

      <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center|bottom"
        android:orientation="vertical">

       <Button
            android:id="@+id/btn_signup"
            style="@style/Widget.AppCompat.Button.Borderless"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:background="@drawable/round"
            android:text="@string/signup"
            android:textColor="@color/color3"
            android:layout_marginBottom="20dp"
            android:textSize="20sp" />
    </LinearLayout>

</LinearLayout>

Solution

  • Use This XML Code

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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"
    tools:context=".MainActivity">
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">
                <!-- Add CONi icon here -->
    
                <EditText
                    android:id="@+id/editlastname"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20sp"
                    android:ems="10"
                    android:hint="lastName"
                    android:inputType="textPersonName" />
    
                <Button
                    android:id="@+id/btn_signup"
                    style="@style/Widget.AppCompat.Button.Borderless"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:text="signup"
                    android:layout_marginBottom="20dp"
                    android:textSize="20sp" />
    
            </LinearLayout>
    
        </ScrollView>
    
    </LinearLayout>