CoordinatorLayout中的大坑

来源:互联网 发布:中科院软件所怎么样 编辑:程序博客网 时间:2024/06/02 00:55

首先来看看布局文件的代码:

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:id="@+id/activity_coor_app_bar"    xmlns:app="http://schemas.android.com/apk/res-auto"    tools:context=".Activity.AppBarLayoutActivity">    <android.support.design.widget.AppBarLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">                <android.support.v7.widget.Toolbar            android:id="@+id/toolbar"            android:layout_width="match_parent"            android:layout_height="?attr/actionBarSize"            android:background="?attr/colorPrimary"            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"            app:layout_scrollFlags="scroll|enterAlways">        </android.support.v7.widget.Toolbar>        <android.support.design.widget.TabLayout            android:id="@+id/tabs"            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.CoordinatorLayout>
CoordinatorLayout不支持listview与scrollView。并且viewpage里如果滑动的布局是list view或者scrollview的话在滑动的时候是不是出现折叠效果的。
如果是recycleview就才会出现折叠的效果。

support 23.1+新增了

ViewCompat.setNestedScrollingEnabled(listView/gridview,true); 

如可以给listview提供nestedscrolling支持,但是只在LOLIPOP+版本上生效。低版本只能用RecyclerView。