2016-11-10 13 views
0

データでいっぱいになったRecyclerViewがあります。スクロールすると、ヘッダーがツールバーを位置に固定せず、結果が上がってしまうだけです。スクロール時にRecyclerView修正ヘッダーを作成する方法

スクロール時にツールバーのヘッダーを非表示にするにはどうすればよいですか?または、スクロール時にRecyclerViewで固定スクロールを簡単に作成できますか?

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.bertho.gmyl.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="@dimen/appbar_padding_top" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"> 

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      app:tabBackground="@drawable/tab_selector" 
      app:tabIndicatorColor="@color/whiteColor" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

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

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end|bottom" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@android:drawable/ic_dialog_email" /> 

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

RecyclerViewレイアウト:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rvArticle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

結果: すべての私のコードはうまく動作します

、それはスクロール

ActivityMainレイアウト上がるヘッダを持つだけで問題ですBefore Scroll

After Scroll

+0

あなたは 'CollapsingToolbarLayout'を使用しようとしましたか? –

答えて

0

android:fitsSystemWindows="false"を設定すると、画面全体(ステータスバーを含む)でアクティビティが描画されます。

詳細infoです。

+0

私が 'android:fitsSystemWindows =" false "'を使うと、私のステータスバーが消えます –

+0

どのテーマを使っていますか? – waqaslam

+0

デフォルト、 'AppTheme' –

関連する問題