【发布时间】:2021-08-12 10:41:18
【问题描述】:
当键盘位于片段中的焦点 EditText 上时,如何将带有 listview 的 EditText 滚动到布局的最顶部?
我设计了一个带有编辑文本和列表视图的自定义微调器,当我单击编辑文本然后编辑文本时,我想要的滚动视图中有近五个微调器,然后它的列表向上滚动并在屏幕上完全可见
发生了什么事,你可以在屏幕截图上看到列表不是完全可见的,它有固定的高度。
【问题讨论】:
当键盘位于片段中的焦点 EditText 上时,如何将带有 listview 的 EditText 滚动到布局的最顶部?
我设计了一个带有编辑文本和列表视图的自定义微调器,当我单击编辑文本然后编辑文本时,我想要的滚动视图中有近五个微调器,然后它的列表向上滚动并在屏幕上完全可见
发生了什么事,你可以在屏幕截图上看到列表不是完全可见的,它有固定的高度。
【问题讨论】:
就是这么简单
您只需将您的 recyclerview/listview 和 editTex 字段放在 ScrollView 中,在您的 recycler 视图中添加 android:nestedScrollingEnabled="false" 即可!
示例代码:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_toolbar">
<EditText
android:id="+@id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="5" />
</ScrollView>
【讨论】:
<activity> 标签中添加 android:windowSoftInputMode="stateHidden|adjustResize" 可能有效
NestedScrollView而不是ScrollView