スクロールコンテンツとして FrameLayout コンテナを使用する AppBarLayout が機能しない 質問する

スクロールコンテンツとして FrameLayout コンテナを使用する AppBarLayout が機能しない 質問する

最新のデザイン ライブラリを使用して、スクロール時にツールバーを非表示/表示するようにしようとしています。問題は、スクロールするコンテンツがフラグメント内にあることです。これを FrameLayout コンテナーに挿入するだけでは機能しません。これが私のアクティビティです。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

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

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

<FrameLayout
    android:id="@+id/navigation_drawer_container"
    android:layout_width="@dimen/navigation_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_nav_drawer_anon" />

そして私の断片:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/pull_to_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>

<TextView
    android:id="@android:id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textSize="18sp"
    android:fontFamily="sans-serif"
    android:color="@color/dark_grey"
    android:padding="60dp"/>

ツールバー:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
style="@style/Widget.MyApp.ActionBar" />

私は公式をフォローしていますドキュメントこのデモ、まだそれがどのように機能するかがわかりません。

ベストアンサー1

フレームレイアウトを次のように置き換えますandroid.support.v4.widget.NestedScrollView

NestedScrollView は ScrollView と似ていますが、Android の新旧両方のバージョンでネストされたスクロールの親と子の両方としての動作をサポートします。ネストされたスクロールはデフォルトで有効になっています。

ドキュメントへのリンク

おすすめ記事