Design

协调者模式

效果

在这里插入图片描述
在这里插入图片描述

常见属性

  • AppBarLayout
    用于折叠,将可折叠的内容写在CollapsingToolbarLayout控制中
    属性:
    contentScrim:折叠后Toolbar显示的颜色
  • CollapsingToolbarLayout:
    可以进行滑动,布局有两种控件可以选择:NestedScrollView 和 RecyclerView
    可以通过滑动来控制上半部分是否折叠
    属性:
    collapsedTitleGravity:折叠后title位于Toolbar的位置
    contentScrim:折叠后Toolbar显示的颜色
    title:显示的文字,可以跟着滑动来改变size
    layout_scrollFlags:设置上半部分滑动的方式
    1.scroll 表示CollapsingToolbarLayout可以滚动
    2.enterAlways 表示底部的滚动控件只要向下滚动,头部就显示出来
    3.enterAlwaysCollapsed 表示当底部滚动控件滚动见顶时,头部显示出来
    4.exitUntilCollapsed 表示头部折叠到最小高度时(Toolbar的高度),就不再折叠
    5.snap 表示在滑动过程中如果停止滑动,则头部会就近折叠(要么恢复原状,要么折叠成一个Toolbar)

详细代码

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentScrim="@color/colorPrimary">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:collapsedTitleGravity="right"
            app:layout_scrollFlags="scroll|snap|exitUntilCollapsed|enterAlwaysCollapsed"
            app:title="Design"
            app:contentScrim="@color/colorPrimary">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/keji"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="50dp"
                app:layout_collapseMode="pin">
            </android.support.v7.widget.Toolbar>

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical"
           android:descendantFocusability="blocksDescendants">

           <TextView
               android:gravity="center"
               android:layout_width="wrap_content"
               android:layout_height="300dp"
               android:text="拉拉"/>
           <TextView
               android:gravity="center"
               android:layout_width="wrap_content"
               android:layout_height="300dp"
               android:text="拉拉"/>
           <TextView
               android:gravity="center"
               android:layout_width="wrap_content"
               android:layout_height="300dp"
               android:text="拉拉"/>

       </LinearLayout>
        
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值