在输入文本时在相对布局(包含在滚动视图中)中添加 EditText 视图时,它会将用户带回活动的顶部,(捕捉到屏幕顶部)使用户无法看到他们正在输入的内容。
复制问题
这是该问题的最小再现:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<ImageView
android:layout_width="100dp"
android:layout_height="1000dp"
android:src="@color/purple_500"/>
<EditText
android:layout_width="400dp"
android:layout_height="100dp"
android:translationY="800dp"/>
</RelativeLayout>
</ScrollView>
到目前为止我尝试过的
到目前为止,我已经尝试添加 <activity android:windowSoftInputMode="stateVisible|adjustResize" .>到 android 清单中,但它没有任何区别并填充 EditText 虽然我找不到其他发生这种情况的情况。
添加wrap_content到android:layout_height="",未解决的问题
编辑
我需要在相对布局中包含线性布局中的编辑文本,如此处所示-https://stackoverflow.com/questions/40316454/edittext-moves-textview-out-of-the-screen-when-they -keyboard-is-opening