1.toolbar 和 Tablayout 显示viewpageindicator,和Toolbar 折叠tablout
借助与com.viewpageindicator.UnderlinePageIndicator实现
布局文件可以省略优化的,其中tabhost等等是可以取消掉的,呃……………………………
注意:不能设置为noactionBar,不然toolbar也会折叠
<p>CoordinatorLayout is intended for two primary use cases:</p> * <ol> * <li>As a top-level application decor or chrome layout</li> * <li>As a container for a specific interaction with one or more child views</li> * </ol>
<?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:layout_width="match_parent" android:layout_height="match_parent" tools:context="date.dingqs.toolbarscrol.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <!-- --> <!--<android.support.v7.widget.Toolbar android:id="@+id/tb" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </android.support.v7.widget.Toolbar> --> <android.support.design.widget.TabLayout android:id="@+id/tl" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|enterAlways" app:tabIndicatorHeight="0dp"></android.support.design.widget.TabLayout> <com.viewpagerindicator.UnderlinePageIndicator android:id="@+id/indicator" android:layout_width="fill_parent" android:layout_height="5px" android:focusable="false" android:focusableInTouchMode="false" /> </android.support.design.widget.AppBarLayout> <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="0" android:background="#ffffff" android:divider="@null" android:focusable="true" android:focusableInTouchMode="true" android:gravity="clip_vertical" android:orientation="horizontal" android:visibility="gone" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout> </TabHost> </android.support.design.widget.CoordinatorLayout>