關於在項目中使用Android5.0的CoordinatorLayout,上滑無效果的問題

  • 貼代碼:android

    <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <!--向上滾動會隱藏的部分要設置app:layout_scrollFlags="scroll"-->
                    <include
                        layout="@layout/item_dynamic_list_item_detail_item"
                        app:layout_scrollFlags="scroll"/>                   
                    <android.support.design.widget.TabLayout
                        android:id="@+id/tl_tab_dynamic_list_item_detail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:theme="@style/ThemeOverlay.AppCompat.Dark"
                        android:background="@color/colorPrimary"/>
             </android.support.design.widget.AppBarLayout>
    
            <android.support.v4.view.ViewPager
                android:id="@+id/vp_dynamic_list_item_detail"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    </android.support.design.widget.CoordinatorLayout>
    
    說明:上面代碼的"include"Tag是引入一個頭部佈局,而我想實現的效果
    是在上移時將這部分隱藏,但效果就是不出來。
  • 嘗試:我將上面提到的」include」外面再嵌套一層LinearLayout,效果出來了,直接貼代碼吧!web

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <!--向上滾動會隱藏的部分要設置app:layout_scrollFlags="scroll"-->
            <LinearLayout
                app:layout_scrollFlags="scroll"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"//換成LinearLayout嵌套設置使用,可行   
                 android:orientation="vertical">
                <include
                    layout="@layout/item_dynamic_list_item_detail_item"/>
            </LinearLayout>
            <android.support.design.widget.TabLayout
                android:id="@+id/tl_tab_dynamic_list_item_detail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:theme="@style/ThemeOverlay.AppCompat.Dark"
                android:background="@color/colorPrimary"/>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.view.ViewPager
            android:id="@+id/vp_dynamic_list_item_detail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    </android.support.design.widget.CoordinatorLayout>
  • 總結:採用」include」引入佈局的方式,在include所在的」<>」裏爲其佈局設置屬性多是無效的,由於我也 沒嘗試其餘嵌套設置屬性的狀況,…有時間將繼續探討app