2017-06-13 11 views
0

RecyclerViewでスクロールするときにツールバーを非表示にするには、アプリでNestedScrollViewを使用しています。問題は、RecyclerViewをNestedScrollViewの中に入れたときに、RecyclerViewのパフォーマンスが非常に悪く、スクロールするときに時間がかかることです。レイアウトRecyclerViewでNestedScrollViewを実行すると、パフォーマンスが大幅に低下する

ここに、RecyclerViewを使用したフラグメントのmyml実装があります。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/colorPrimary" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark" 
    android:elevation="0dp" 
    android:visibility="gone" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:layout_scrollFlags="scroll|enterAlways"/> 

<android.support.v4.widget.NestedScrollView 
    android:isScrollContainer="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/toolbar" 
    android:background="@color/light_gray" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:clickable="true" /> 

</android.support.v4.widget.NestedScrollView> 

</RelativeLayout> 

これは、ViewPagerの内部にあるフラグメントです。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/coordinatorLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appBar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    app:elevation="0dp"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark" 
     android:elevation="0dp" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="scroll|enterAlways"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="fill_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_gravity="left|center_vertical" 
      android:layout_weight="1" 
      android:gravity="left|center_vertical" 
      android:text="@string/app_name" 
      android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" 
      android:textColor="@color/white" 
      android:textSize="18sp"/> 

    </android.support.v7.widget.Toolbar> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_below="@id/appBar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:visibility="gone" 
     app:tabIndicatorColor="@android:color/white" 
     app:tabMode="scrollable" 
     app:tabSelectedTextColor="@android:color/white" 
     app:tabIndicatorHeight="3dp" 
     app:tabTextColor="@color/white"/> 

</android.support.v4.view.ViewPager> 

<ProgressBar 
    android:id="@+id/eventsProgress" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center"/> 

<FrameLayout 
    android:id="@+id/search_fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize" 
    /> 

</android.support.design.widget.CoordinatorLayout> 

NestedScrollViewを削除し、はるかに優れたパフォーマンスでRecyclerViewだけで結果を残したが、その後、私は隠れツールバーを持っていない。ここでViewPagerと他のレイアウトです。

何か間違っていますか?

+0

どこかで 'CoordinatorLayout'を使用していますか?このレイアウトは別のレイアウトの一部ですか、それともスタンドアロンですか? –

+0

はい、申し訳ありません。このレイアウトは、ViewPagerの中に入る断片のためのものです。 ViewPagerでさらに情報とレイアウトを追加しました。 – JoeyCK

答えて

0

はい、Toolbarの場合、CoordinatorLayoutAppBarを試してください。こうすることで、適切なscrollBehaviorを使用することで、リストがスクロールされたときにツールバーを隠す/折りたたむことができます。

0

スクロールビュー内にリサイクラビューを配置すると、デフォルトではスクロールビュースクロールはリサイクラビュースクロールではなく動作します。 これを修正するには、android:nestedScrollingEnabled="true"、recyclerViewを試してみてください。 これで問題が解決されることを願っています。

+0

私はすでにフラグメント内のsetNestedScrollingEnabled(false)を呼び出しています – JoeyCK

+0

true ...:P –

関連する問題