我有一个带有ViewPager和水平RecyclerViews的ScrollView布局,我的问题是当我隐藏键盘时,页面向下滚动了一下。我尝试将windowSoftInputMode更改为adjustNothing,它确实解决了问题,但键盘隐藏了SearchView建议。
出于某种原因,它只会在页面达到一定长度时发生,因为如果我删除一个RecyclerView或ViewPager,则不会发生这种情况。
我发现了这个问题的两个解决方法,一个是在键盘弹出时将布局的可见性更改为隐藏时恢复可见,第二个是在查询文本失去焦点时隐藏键盘和SearchView,但我真的想找到解决这个问题的正确方法。
以下是问题视频和布局代码:
https://www.youtube.com/watch?v=hyexsQz8ja0
<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"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true">
<RelativeLayout
android:id="@+id/fragment_courses_relativeLayout_viewPager"
android:layout_height="200dp"
android:layout_width="match_parent">
<ViewPager
android:id="@+id/main_catalog_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
<InkPageIndicator
android:id="@+id/main_catalog_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:visibility="gone"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_courses_software_see_all"
android:background="?attr/selectableItemBackground"
android:visibility="gone"
android:clickable="true"
android:minHeight="48.0dip">
<FrameLayout
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/course_type_software"
android:textSize="20.0sp"
android:textColor="?android:textColorPrimary"
android:layout_marginStart="16dp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_all"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.Button"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_courses_software_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingTop="4dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_courses_cyber_see_all"
android:background="?attr/selectableItemBackground"
android:visibility="gone"
android:clickable="true"
android:minHeight="48.0dip">
<FrameLayout
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/course_type_cyber"
android:textSize="20.0sp"
android:textColor="?android:textColorPrimary"
android:layout_marginStart="16dp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_all"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.Button"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_courses_cyber_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingTop="4dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_courses_it_see_all"
android:background="?attr/selectableItemBackground"
android:visibility="gone"
android:clickable="true"
android:minHeight="48.0dip">
<FrameLayout
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/course_type_it"
android:textSize="20.0sp"
android:textColor="?android:textColorPrimary"
android:layout_marginStart="16dp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_all"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.Button"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_courses_it_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingTop="4dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_courses_tools_see_all"
android:background="?attr/selectableItemBackground"
android:visibility="gone"
android:clickable="true"
android:minHeight="48.0dip">
<FrameLayout
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/course_type_tools"
android:textSize="20.0sp"
android:textColor="?android:textColorPrimary"
android:layout_marginStart="16dp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_all"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.Button"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_courses_tools_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingTop="4dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fragment_courses_system_see_all"
android:background="?attr/selectableItemBackground"
android:visibility="gone"
android:clickable="true"
android:minHeight="48.0dip">
<FrameLayout
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/course_type_system"
android:textSize="20.0sp"
android:textColor="?android:textColorPrimary"
android:layout_marginStart="16dp" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/see_all"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.Button"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/fragment_courses_system_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingTop="4dp"/>
</LinearLayout>
答案 0 :(得分:1)
我设法通过将以下属性添加到ScrollView的最顶层视图来解决问题,在我的例子中是LinearLayout:
android:focusableInTouchMode="true"
原来这个问题与ScrollView中的RecyclerViews有关,并在此报告给Google Issue 81854