I'm facing an issue with ScrollView in my newly created Android app. Previously, ScrollView worked perfectly in my projects, but now with the introduction of Edge-to-Edge in Android, ScrollView is not working properly on any page.
The issue is more noticeable when dealing with long forms. After filling a field and dismissing the keyboard, the ScrollView doesn't scroll to the next input field as expected.
I've already tried solutions like:
- Adding
android:windowSoftInputMode="adjustResize"
in the manifest. - Using
view.post { scrollView.fullScroll(View.FOCUS_DOWN) }
. - Applying
fillViewPort
in the ScrollView.
None of these solutions seem to fix the issue.
Has anyone else encountered this problem or found a working solution?
Login page with Relative Layout as Root
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=";
xmlns:app=";
xmlns:tools=";
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/main"
tools:context=".activities.LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:title="Login"
app:titleCentered="true"
app:titleTextColor="?attr/colorOnPrimary" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="80dp"
android:orientation="vertical">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etEmailTextField"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="8dp"
android:hint="Enter Email">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etPasswordTextField"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:hint="Enter Password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:padding="20dp"
android:text="LOGIN"
android:textAllCaps="true"
android:textColor="?attr/colorOnPrimary"
android:textSize="16sp"
app:backgroundTint="?attr/colorPrimary"
app:cornerRadius="10dp"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
<include
android:id="@+id/layoutLoader"
layout="@layout/layout_loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
Login Page with Constraint Layout as a root
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=";
xmlns:app=";
xmlns:tools=";
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LoginActivity">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:title="Login"
app:titleCentered="true"
app:titleTextColor="?attr/colorOnPrimary" />
<LinearLayout
android:id="@+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/toolbar">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="vertical">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/logo" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etEmailTextField"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="8dp"
android:hint="Enter Email">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/etPasswordTextField"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:hint="Enter Password">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="15dp"
android:text="Login"
android:textAllCaps="true"
android:textColor="?attr/colorOnPrimary"
android:textSize="16sp"
app:backgroundTint="?attr/colorPrimary"
app:cornerRadius="8dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<include
android:id="@+id/layoutLoader"
layout="@layout/layout_loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</androidx.constraintlayout.widget.ConstraintLayout>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744719611a4589831.html
评论列表(0条)