現在仿360手機助手,簡書布局效果的案例,越來越多,之前我寫過 FloatIndicatorLayout ,發出來之後,還是有不少朋友在看,也有朋友告訴我可以用CoordinatorLayout去實作這個效果,之前對協調器布局了解的比較少,這兩天抽空看了一下,不僅感慨,還是谷歌的大神牛逼!
先看png預覽,這裡是 gif效果圖 源碼
Paste_Image.png
再看代碼
<pre>
<
android.support.design.widget.CoordinatorLayoutxmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:cool="
http://schemas.android.com/apk/res-autoxmlns:tools="
http://schemas.android.com/toolsandroid:id="@+id/co_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/ab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/co_to_layout"
android:layout_width="match_parent"
android:layout_height="270dp"
android:background="#DD009688"
cool:collapsedTitleTextAppearance="@style/ToolBarTitleText"
cool:contentScrim="#009688"
cool:expandedTitleMarginEnd="48dp"
cool:expandedTitleMarginStart="48dp"
cool:expandedTitleTextAppearance="@style/transparentText"
cool:layout_scrollFlags="scroll|enterAlways">
<!-- cool:layout_scrollFlags="scroll|exitUntilCollapsed"-->
<LinearLayout
android:id="@+id/layout_head"
cool:layout_collapseMode="pin"
cool:layout_collapseParallaxMultiplier="0.7">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:padding="20dp">
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
cool:layout_collapseMode="pin"
cool:popupTheme="@style/ThemeOverlay.AppCompat.Light"
cool:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.CollapsingToolbarLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#EE009688"/>
<github.hellojp.tabsindicator.TabsIndicator
xmlns:tabsIndicator="http://schemas.android.com/apk/res-auto"
android:id="@+id/ti"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="#009688"
tabsIndicator:dividerColor="#E0F2F1"
tabsIndicator:dividerVerticalMargin="10dp"
tabsIndicator:dividerWidth="2dp"
tabsIndicator:hasDivider="true"
tabsIndicator:lineColor="#00695C"
tabsIndicator:lineHeight="2dp"
tabsIndicator:lineMarginTab="20dp"
tabsIndicator:linePosition="bottom"
tabsIndicator:textBackgroundResId="@drawable/selector_view_tabs_item"
tabsIndicator:textColor="@drawable/selector_tab"
tabsIndicator:textSizeNormal="14sp"
tabsIndicator:textSizeSelected="18sp"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
cool:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</pre>
<LinearLayout xmlns:android="
android:orientation="vertical"
tools:ignore="ContentDescription,UselessParent">
<github.aspsine.swipetoloadlayout.SwipeToLoadLayout
xmlns:swipeToLoadLayout="http://schemas.android.com/apk/res-auto"
android:id="@+id/stll"
android:layout_width="match_parent"
android:layout_height="match_parent"
swipeToLoadLayout:default_to_loading_more_scrolling_duration="500"
swipeToLoadLayout:default_to_refreshing_scrolling_duration="1000"
swipeToLoadLayout:load_more_complete_delay_duration="0"
swipeToLoadLayout:load_more_final_drag_offset="@dimen/load_more_final_offset_google"
swipeToLoadLayout:load_more_trigger_offset="@dimen/load_more_trigger_offset_google"
swipeToLoadLayout:refresh_complete_delay_duration="0"
swipeToLoadLayout:refresh_final_drag_offset="@dimen/refresh_final_offset_google"
swipeToLoadLayout:refresh_trigger_offset="@dimen/refresh_trigger_offset_google"
swipeToLoadLayout:swipe_style="above">
<include
android:id="@id/swipe_refresh_header"
layout="@layout/layout_google_hook_header"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/swipe_target"
tools:listitem="@layout/item_fragment_game_before_score"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include
android:id="@id/swipe_load_more_footer"
layout="@layout/layout_google_footer"
/>
</github.aspsine.swipetoloadlayout.SwipeToLoadLayout>
</LinearLayout>