skip to Main Content

I have a scroll view wrapping a LinearLayout , i have a button at the end of the layout , the entire layout is visible and scrollable but the button at the end is not visible , it becomes visible if i put it at first or make space for the button without the scroll view.

code

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/container1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20sp"
        android:orientation="horizontal"
        android:padding="25sp"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="25sp"
            android:layout_weight="1"
            android:fontFamily="@font/roboto_bold"
            android:text="TEST"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="25sp"
            android:contentDescription="close"
            android:src="@drawable/test" />
    </LinearLayout>

    <ScrollView
        android:id="@+id/nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/container1">

        <LinearLayout
            android:id="@+id/linearLayout5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="25sp">


            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />


            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />


            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />



            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />


            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />


            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="TEXT"
                android:importantForAutofill="no"
                android:inputType="text"
                android:padding="40sp"
                android:textSize="22sp"
                android:textStyle="bold" />


            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:backgroundTint="@color/blue"
                android:text="@string/submit"
                android:textColor="@color/white" />

        </LinearLayout>
    </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

I have tried changing to androidx.appcompat.widget.AppCompatButton , use image button but still no avail,
I tried to give hard coded height and width still it’s not visible.

After some playing around i just found out that my last child is not visible be it button, text or any other

Any help is appreciated

2

Answers


  1. You just have to add this line of code inside your Button Widget.

    android:layout_marginBottom="50dp"

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:backgroundTint="@color/blue"
        android:text="@string/submit"
        android:textColor="@color/white"
        android:layout_marginBottom="50dp" // Add this line
    />
    

    This will solve your problem. Thank you.

    Login or Signup to reply.
  2. You just need to change Scrollview code with

     <ScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/container1">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search