2016-11-22 17 views
0

ListViewがスクロールしているときにツールバーを表示/非表示にしたい。私はツールバーに含まれるCorrdinatorLayoutを持っています。私はapp:layout_scrollFlags = "scroll | enterAlways"属性をツールバーに追加します。次に、app:layout_behavior = "@ string/appbar_scrolling_view_behavior"属性を持つRelativeLayoutを持つcontent_minレイアウト内のListviewを持っています。私は、listviewのスクロールイベントに反応しないCoordinatorLayout -Toolbarの中にcontent_mainレイアウトを含めました。この機能はRecyclerViewでのみ動作し、リストビューでは動作しませんか?ツールバーがスクロールイベントに反応しない

<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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.era.www.onmovie.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    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.design.widget.AppBarLayout> 


<include layout="@layout/content_main" /> 

content_mainレイアウト

<RelativeLayout 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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.era.www.onmovie.MainActivity" 
tools:showIn="@layout/activity_main"> 


<ListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 


<TextView 
    android:id="@+id/empty_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

<ProgressBar 
    android:id="@+id/progress_bar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

答えて

0

スクロール動作はListViewとアウトオブボックスRecyclerViewではなく、で動作します。これは、スクロール動作がNestedScrollingChildインターフェイスを実装するスクロールコンポーネントを必要とするためです。このインターフェイスはRecyclerViewで実装されていますが、ListViewでは実装されていません。

ListViewアダプターをRecyclerViewアダプターに変換し、RecyclerViewを使用することをお勧めします。

ListViewNestedScrollViewの内側に配置する方法がいくつかありますが、これはスクロールの動作になります。私はこれをお勧めしませんが、そうすれば、ListViewNestedScrollViewの中にラップし、ツールバーをスクロールさせるための解決策が見つかります。

関連する問題