Android理论CoordinatorLayout今日看点

Android 之协调伸缩CoordinatorLayout,C

2016-07-19  本文已影响3689人  AndroidWanLi

前言#


 上一篇文章承诺会讲解折叠伸缩的效果,所以废话不多说

上gif#


Gank2.gif

一句话#


当你初次看见这样的效果可能会觉得实现起来比较麻烦。而我告诉你,只需要正确的配置XML中的控件即可.

上代码#


请结合讲解模块一起阅读

<?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"
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
     
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:minHeight="?attr/actionBarSize"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="40dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
         
            <ImageView
                android:id="@+id/image_collapsing"
                android:layout_width="match_parent"
                android:layout_height="380dp"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                android:transitionName="@string/transition_fab"
                app:layout_collapseMode="parallax" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_collapsing"
                android:layout_width="match_parent"
                android:layout_height="?android:actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>

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


    <android.support.v7.widget.RecyclerView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v7.widget.RecyclerView>




    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_detail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:clickable="true"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right|end" />        

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

讲解#


关键控件###

结束#


如果你认真阅读过我的文章,并且认真的看过xml布局
那么细心的你一定会发现在CollapsingToolbarLayout中还有以下属性。
以这样的方式讲解,主要是希望在你阅读的时候结合上下文去思考。

 contentScrim             -    设置当完全折叠(收缩)后的背景颜色。
 expandedTitleMarginEnd   -    没有扩张的时候标题显示的位置
 expandedTitleMarginStart -    扩张的时候标题向左填充的距离。

 statusBarScrim - 设置折叠时状态栏的颜色
上一篇下一篇

猜你喜欢

热点阅读