安卓5.0推出的协调者布局,其实关键的代码都在xml布局中


今天想做一个滑动到屏幕顶端的就停在哪里大图title,搜了一下资料,其实so  easy,直接上代码


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <!--协调者布局-->
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--第一个view必须是AppBarLayout-->
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            android:layout_height="wrap_content">

            <!--将需要画上去的头头用CollapsingToolbarLayout包裹 一定要添加属性layout_scrollFlags-->
            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:layout_height="100dp">
                <android.support.v4.view.ViewPager
                    android:id="@+id/view_pager_head"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                </android.support.v4.view.ViewPager>

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

            <!--将需要固定的悬浮在上面的头放在这里-->
             <TextView
                 android:background="#ff0000"
                 android:gravity="center"
                 android:text="我是需要固定的头头"
                 android:layout_width="match_parent"
                 android:layout_height="50dp" />
        </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rec"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>


大家看到这里使用的是RecyclerView,这个android 5.0推出来的心特性,试想一下换成listView 或者Gridview行不行呢?


答案是肯定不行的,listView  和GridView是android5.0之前推出了,和协调者布局一起使用时没有效果的,只能使用RecyclerView啦




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值