【问题标题】:How to scroll an EditText with listview to the very top of the layout in fragment?如何将带有列表视图的 EditText 滚动到片段中布局的最顶部?
【发布时间】:2021-08-12 10:41:18
【问题描述】:

当键盘位于片段中的焦点 EditText 上时,如何将带有 listview 的 EditText 滚动到布局的最顶部?

我设计了一个带有编辑文本和列表视图的自定义微调器,当我单击编辑文本然后编辑文本时,我想要的滚动视图中有近五个微调器,然后它的列表向上滚动并在屏幕上完全可见

发生了什么事,你可以在屏幕截图上看到列表不是完全可见的,它有固定的高度。

【问题讨论】:

    标签: java android xml


    【解决方案1】:

    就是这么简单 您只需将您的 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> 
    

    【讨论】:

    • 这不起作用我需要在键盘启动时自动滚动视图
    • 在 manifest.xml 文件的 &lt;activity&gt; 标签中添加 android:windowSoftInputMode="stateHidden|adjustResize" 可能有效
    • 在清单中添加但它在片段中不起作用我也在片段 getActivity()?.getWindow()?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    • 你试过NestedScrollView而不是ScrollView
    • 是的,我也尝试使用坐标布局的 NestedScrollView,但它也不起作用
    猜你喜欢
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    相关资源
    最近更新 更多