Editext 和键盘将新条目重叠到回收器视图
我正在尝试创建一个注释应用程序,用户可以通过按键盘上的“完成”快速一个接一个地输入注释,而不必为每个条目再次按 editText
布局是约束布局。
我将 editText 限制在 recyclerview 下方
我希望在输入新条目时始终在屏幕上看到我的编辑文本和插入的最后一个元素
当我在某个点之后将条目添加到回收器视图时,问题就会发生,我的 editText 开始与新条目重叠 仅当我退出键盘后,
我才能看到新条目
,并且当我再次单击 editText 后......键盘布局覆盖了最新条目
这是我的问题的快速 gif
这种重叠不会发生在运行 lollipop (api 21) 的模拟设备上,
但会发生在模拟设备 api 24 和 api 30 上
,如果可能的话,我还想添加添加/删除 recyclerview 中的元素时向上/向下滑动 editText 的动画。
这是导航视图更新 (1) 的布局代码
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="80dp">
<TextView
android:id="@+id/hello_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO,"
android:layout_margin="16dp"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/username_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USER"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="@+id/hello_tv"
app:layout_constraintStart_toStartOf="@+id/hello_tv"
app:layout_constraintTop_toBottomOf="@+id/hello_tv" />
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="200dp"
android:background="#4E4C4C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/nav_lists_title_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="My Lists"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/nav_lists_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nav_lists_title_tv"
tools:itemCount="15"
tools:listitem="@layout/navigation_body_item_layout" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nav_add_list_til"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
app:boxBackgroundColor="#00ffffff"
app:boxStrokeWidth="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="add new list"
app:endIconDrawable="@drawable/ic_baseline_add_circle_outline_24"
app:endIconMode="custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nav_lists_rv">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nav_add_list_et"
android:imeOptions="actionDone"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</com.google.android.material.navigation.NavigationView>
:-
我通过每次添加新条目时以编程方式滚动回收器视图来解决问题。
但是在从 recyclerview 添加或删除元素时,动画 editTxt 滑动效果不佳
I'm trying to create a notes app where user can enter notes one after the other quickly by pressing done on their keyboard without having to press the editText again for every entry
The layout is a Constraint Layout.
I constrained a editText below the recyclerview
I want my edit text and the last element inserted to be seen on the screen always when entering new entries
the problem happens when I add entries to the recycler view after a certain point my editText start overlapping over the new entries
only after I exit the keyboard I'm able to see the new entries
and When I click on the editText again after.. the keyboard layout covers the latest entries
Here is a quick gif of my problem
This overlap didnt occur on a emulated device running lollipop (api 21)
but it happens on emulated devices api 24 and api 30
And If it's possible I would also like to add animations to slide the editText up/down when elements in recyclerview gets added/deleted.
Here is the layout code of the navigationview
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="80dp">
<TextView
android:id="@+id/hello_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO,"
android:layout_margin="16dp"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/username_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USER"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="@+id/hello_tv"
app:layout_constraintStart_toStartOf="@+id/hello_tv"
app:layout_constraintTop_toBottomOf="@+id/hello_tv" />
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="200dp"
android:background="#4E4C4C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/nav_lists_title_tv"
style="@style/titles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="My Lists"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/nav_lists_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nav_lists_title_tv"
tools:itemCount="15"
tools:listitem="@layout/navigation_body_item_layout" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nav_add_list_til"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
app:boxBackgroundColor="#00ffffff"
app:boxStrokeWidth="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="add new list"
app:endIconDrawable="@drawable/ic_baseline_add_circle_outline_24"
app:endIconMode="custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nav_lists_rv">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nav_add_list_et"
android:imeOptions="actionDone"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</com.google.android.material.navigation.NavigationView>
Update (1) :-
I fixed the problem by programmatically scrolling the recyclerview every time I add a new entry.
But no luck on animating editTxt sliding when adding or deleting elements from the recyclerview
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 AndroidManifest.xml 上,在
标记内添加android:windowSoftInputMode="adjustResize"
,例如:on AndroidManifest.xml add
android:windowSoftInputMode="adjustResize"
inside your<activity>
tag for example :