【发布时间】:2021-09-20 00:26:31
【问题描述】:
当在相对布局(包含在滚动视图中)中添加 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-什么时候打开键盘
【问题讨论】:
-
这可能是因为你的 RecyclerView 有 match_parent 而不是 wrap_content。试试看
-
我可以知道你为什么将 ImageView 的高度设置为 1000dp 吗?
-
这只是证明当输入@vijay 时 EditText 不在屏幕上
-
您是否考虑过使用 ConstraintLayout 而不是 RelativeLayout(已弃用)?
标签: java android xml android-layout android-edittext