Home > Software design >  Scrollview not working when focus in EditText on Android studio
Scrollview not working when focus in EditText on Android studio

Time:08-31

I'm confused why it doesn't scroll down when my cursor focus inside the EditText, in order to scroll you just need to click to the another to scroll down, it there any way how to handle this?

I've Already used this command inside Layout but it doesn't work, need help

android:focusable="true"
android:focusableInTouchMode="true"

enter image description here

**The layout above is the child of this activity so this is the parent it's just like onBoarding Screen using ViewPager

enter image description here

The parent xml

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Scanner.ScanCashCard">

    <HorizontalScrollView
        android:id="@ id/horizontalScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" >

        <androidx.viewpager.widget.ViewPager
            android:id="@ id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </HorizontalScrollView>
    <LinearLayout
        android:id="@ id/layoutDots"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="@color/primary"
        app:layout_constraintBottom_toBottomOf="parent" />

    <TextView
        android:id="@ id/tvPrev"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_marginBottom="25dp"
        android:text="PREV"
        android:textColor="@android:color/white"
        android:textSize="15sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@ id/tvNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_marginBottom="25dp"
        android:text="NEXT"
        android:textColor="@android:color/white"
        android:textSize="15sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <LinearLayout
        android:id="@ id/linear2"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal"
        android:padding="5dp"
        app:layout_constraintBottom_toBottomOf="parent">
        <ImageView
            android:id ="@ id/imageIv"
            android:height ="60dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
    
</androidx.constraintlayout.widget.ConstraintLayout>

Updated I tried android:fillViewport="true" like in the following but it didn't work

enter image description here

Updated Code

Child xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/primary"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <TextView
        android:id="@ id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:layout_margin="15dp"
        android:textStyle="bold"
        android:text="I. Demographics"
        android:fontFamily="sans-serif-condensed"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="15dp" />

    <ScrollView
        android:background="@color/white"
        android:layout_width="wrap_content"
        android:layout_height="660dp"
        android:fillViewport="true"
        >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:layout_marginRight="10dp"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:orientation="vertical">

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_hhid"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="30dp"
                    android:layout_marginRight="10dp"
                    app:errorEnabled="true"
                    app:counterEnabled="true"
                    app:counterMaxLength="30"
                    app:endIconMode="clear_text"
                    app:helperText="Search Household ID!"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_hh">

                    <EditText
                        android:id="@ id/edtHhId"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="160310001-"
                        android:hint="Household no."
                        android:inputType="text"
                        android:maxLength="30" />
                </com.google.android.material.textfield.TextInputLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right">

                    <Button
                        android:id="@ id/btnSearchHh"
                        android:layout_width="100dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="10dp"
                        android:padding="10dp"
                        android:textSize="12dp"
                        android:text="Search"
                        android:textStyle="bold"
                        />


                </LinearLayout>


                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_fullname"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_search"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="15dp"
                    android:layout_marginRight="10dp"
                    app:endIconMode="clear_text"
                    app:helperText="Required"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_person">

                    <EditText
                        android:id="@ id/edtFullname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Full name:"
                        android:inputType="text" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_clientstatus"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_fullname"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    app:helperText="Required"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_client">

                    <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                        android:id="@ id/spinnerClientStatus"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Client status"
                        android:inputType="none" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_address"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_clientstatus"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    app:endIconMode="clear_text"
                    app:helperText="Required"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_baseline_location_on_24">

                    <EditText
                        android:id="@ id/edtAddress"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Address"
                        android:inputType="text" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@ id/til_sex"
                    app:helperText="Required"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="10dp"
                    app:helperTextTextColor="@color/validation"
                    android:layout_below="@ id/til_address"
                    app:startIconDrawable="@drawable/ic_baseline_supervised_user_circle_24"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu">
                    <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                        android:id="@ id/spinnerSex"
                        android:layout_width= "match_parent"
                        android:hint="Sex"
                        android:layout_height="wrap_content"
                        />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_contact_no"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_sex"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    app:endIconMode="clear_text"
                    app:helperText="Required"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_baseline_phone_android_24">

                    <EditText
                        android:id="@ id/edtContactNo"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Contact No."
                        android:inputType="number" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_set"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_contact_no"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    app:endIconMode="clear_text"
                    app:helperText="Required"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_assigned">

                    <EditText
                        android:id="@ id/edtSet"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Set"
                        android:inputType="number" />
                </com.google.android.material.textfield.TextInputLayout>



                <com.google.android.material.textfield.TextInputLayout
                    android:id="@ id/til_assigned"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@ id/til_contact_no"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    app:endIconMode="clear_text"
                    app:helperTextTextColor="@color/validation"
                    app:startIconDrawable="@drawable/ic_baseline_person_24">

                    <EditText
                        android:id="@ id/edtAssigned"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Assigned C/ML"
                        android:inputType="text" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@ id/til_minor_grantee"
                    android:layout_marginTop="20dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginBottom="80dp"
                    app:helperTextTextColor="@color/validation"
                    android:layout_below="@ id/til_assigned"
                    app:startIconDrawable="@drawable/ic_baseline_escalator_warning_24"
                    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu">
                    <androidx.appcompat.widget.AppCompatAutoCompleteTextView
                        android:id="@ id/spinnerMinorGrantee"
                        android:layout_width= "match_parent"
                        android:hint="Minor Grantee"
                        android:layout_height="wrap_content"
                        />
                </com.google.android.material.textfield.TextInputLayout>

             </LinearLayout>


        </RelativeLayout>
    </ScrollView>
</LinearLayout>

CodePudding user response:

Change the height of the ScrollView like this. And Also add app:layout_constraintTop_toBottomOf and app:layout_constraintBottom_toBottomOf.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@ id/textView1"
    app:layout_constraintBottom_toBottomOf="parent">

If first doesn't work, try second one.

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:fillViewport="true">

May be this will fix your issue.

CodePudding user response:

It works fine now I just change my HorizontalScrollView to ScrollView

  • Related