使用新的导航体系结构组件,滚动视图不会按片段向上滚动

问题描述

我有一个片段,已经使用现代的导航UI导航到该片段。问题在于滚动视图不会开始滚动,除非视图很长。没关系,我理解,但是出现了一个问题:打开键盘时,屏幕底部的“编辑”文本输入被隐藏,因此您键入时看不到,因此需要滚动视图向下滚动,以便可以在键盘上方向上滚动视图

有没有一种方法可以启动滚动视图,以便当键盘隐藏“编辑”文本输入时,我仍然可以向上滚动并查看键入的内容

我的导航主机片段

<fragment
            android:id="@+id/nav_host_fragment"
            android:layout_below="@+id/app_bar_layout"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/navigation_graph"
            android:layout_above="@+id/bottom_nav"/>

我的片段布局具有滚动视图,但不滚动

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.ScrollFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_margin="5dp">


        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="First Name"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Second Name"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Phone Number"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Gender"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="country"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="province"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="County"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="province"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="region"
            android:layout_margin="5dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="village"
            android:layout_margin="5dp"/>
        
    </LinearLayout>

</ScrollView>

如果我添加了更多视图并且布局足够长,则滚动视图可以正常工作,但是当视图尚未到达底部键盘隐藏了视图且我无法看到正在键入的内容时,滚动视图无法滚动编辑文字

我尝试使用嵌套滚动视图并设置

app:layout_behavior="@string/appbar_scrolling_view_behavior"

但仍然无法正常工作。

我还尝试将以下属性设置为滚动视图

    android:isScrollContainer="false"
    android:fitsSystemWindows="true"
    android:fillViewport="true"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)