2016-07-16 137 views
1

我有一個與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> 

回答

1

我設法解決通過添加下面的屬性到最頂部的視圖問題ScrollView,在我的情況下是LinearLayout:

android:focusableInTouchMode="true" 

原來這個問題與ScrollView裏面的RecyclerViews有關,這裏向Google報告Issue 81854