我希望屏幕在键盘打开时自动向上滚动,这样用户就可以看到他写的东西。我找到的解决方案是更改清单并使用adjustpan或adjustresize。我两个都用了,但还是没用。我的错在哪里?提前谢谢。xml格式:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@color/white"
tools:context=".auth.LoginActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@mipmap/img_login"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
tools:ignore="MissingConstraints" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-100dp"
android:orientation="vertical"
android:background="@drawable/login_back">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="@color/customColor"
android:gravity="center"
android:textSize="30dp"
android:layout_marginTop="42dp"/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:focusableInTouchMode="true"
android:hint="User Name"
android:layoutDirection="rtl"
android:textColorHint="@color/customColor"
>
<EditText
android:id="@+id/acLogin_edtUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="ltr"
android:inputType="textEmailAddress"
android:textSize="16dp"
android:singleLine="true"
android:textColor="@color/customColor"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:focusableInTouchMode="true"
android:hint="Password"
android:layoutDirection="rtl"
android:textColorHint="@color/customColor"
>
<EditText
android:id="@+id/acLogin_edtPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textSize="16dp"
android:textColor="@color/customColor"
/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="42dp"
android:layout_gravity="center"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="@color/customColor"
app:cardCornerRadius="8dp">
<TextView
android:id="@+id/acLogin_txtLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Login"
android:textColor="#ffffff"
android:textSize="18dp" />
<ProgressBar
android:id="@+id/acLogin_prgLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:visibility="gone" />
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="48dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Don't have any account?"
android:gravity="bottom"
android:layout_marginLeft="58dp"
android:textColor="@color/customColor"
android:textSize="16dp"/>
<TextView
android:id="@+id/acLogin_txtSignUp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:gravity="bottom"
android:text="Sign Up"
android:textColor="@color/customColor"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="200dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
我将清单更改为:
<activity android:name=".auth.LoginActivity"
android:windowSoftInputMode="adjustPan | adjustResize"/>
暂无答案!
目前还没有任何答案,快来回答吧!