无图说卵,先上图

jianshu-top.gif

查阅资料后,发现网上大部分都是用这种方法实现的:

多写一个和需要悬浮的部分一模一样的layout,先把浮动区域的可见性设置为gone。当浮动区域滑动到顶部的时候,就把浮动区域B的可见性设置为VISIBLE。这样看起来就像悬浮在顶部不动了。

具体看下边文章 :

高仿美团app,浮动layout滑动到顶部悬停效果

Android实例-仿美团app,浮动layout滑动到顶部悬停效果

这里介绍的是另外一种方式:

使用design包中的控件

<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"
android:fitsSystemWindows="true"
tools:context="com.peipei.app.MainActivity"> <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"> <android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll"
app:contentScrim="#000000"
android:layout_width="match_parent"
android:layout_height="220dp"> <TextView
android:text="banner区域"
android:gravity="center"
android:textColor="#ffffff"
android:background="#987545"
android:layout_width="match_parent"
android:layout_height="220dp"/> </android.support.design.widget.CollapsingToolbarLayout> <TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="悬浮的部分"/> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text"/> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout>

实现步骤:

  1. 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
  2. 将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
  3. 给滚动的NestedScroolView设置
    app:layout_behavior="@String/appbar_scrolling_view_behavior"
    就大功告成了(记得根布局要是CoordinatorLayout)

最终效果:

damo-jianshu-top.gif

来自:http://www.jianshu.com/p/abdb9828a00d

Android滑动到顶部悬停的更多相关文章

  1. Android 滑动定位+吸附悬停效果实现

    在前两篇文章中,分别介绍了tablayout+scrollview 和 tablayout+recyclerview 实现的滑动定位的功能,文章链接: Android 实现锚点定位 Android t ...

  2. Android ScrollView监听滑动到顶部和底部的两种方式(你可能不知道的细节)

    Android ScrollView监听滑动到顶部和底部,虽然网上很多资料都有说,但是不全,而且有些细节没说清楚 使用场景: 1. 做一些复杂动画的时候,需要动态判断当前的ScrollView是否滚动 ...

  3. android去掉滑动到顶部和底部的阴影

    android去掉滑动到顶部和底部的阴影 <ListView android:id="@+id/listView" android:layout_width="ma ...

  4. Android 滑动效果进阶篇(六)—— 倒影效果

    上篇介绍了使用Animation实现3D动画旋转翻页效果,现在介绍图片倒影实现,先看效果图 本示例主要通过自定义Gallery和ImageAdapter(继承自BaseAdapter)实现 1.倒影绘 ...

  5. 关于Android滑动冲突的解决方法(二)

    之前的一遍学习笔记主要就Android滑动冲突中,在不同方向的滑动所造成冲突进行了了解,这样的冲突非常easy理解,当然也非常easy解决.今天,就同方向的滑动所造成的冲突进行一下了解,这里就先以垂直 ...

  6. Android中隐藏顶部状态栏的那些坑——Android开发之路3

    Android中隐藏顶部状态栏的那些坑 先看看常规的隐藏状态栏的方法: 方法一: @Override protected void onCreate(Bundle savedInstanceState ...

  7. 十六、Android 滑动效果汇总

    Android 滑动效果入门篇(一)—— ViewFlipper Android 滑动效果入门篇(二)—— Gallery Android 滑动效果基础篇(三)—— Gallery仿图像集浏览 And ...

  8. Android滑动动画ViewFlipper和视频播放VideoView的使用

    Android滑动动画,可以用ViewPager或者ViewFlipper实现. ViewPager自带触摸滑动功能,结合Fragment使用很好,来自补充组件android-support-v4.j ...

  9. android滑动基础篇 - 触屏显示信息

    效果图: 代码部分: activity类代码: package com.TouchView; /* * android滑动基础篇 * */ import android.app.Activity; i ...

随机推荐

  1. typeof 和 instanceof 的区别

    在JavaScript中我们想得到一个变量的类型,我们一般会用typeof 得到这个类型的 字符串,但是对于引用类型,typeof始终会返回一个"object",在我们js中有十个 ...

  2. jsp&servlet报红线javax.servlet.jsp.XXXX cannot be resolved to a type类似错误解决办法

    javax.servlet.jsp.JspException cannot be resolved to a type javax.servlet.jsp.PageContext cannot be ...

  3. AIX 5.3下创建逻辑卷、添加文件系统并挂载

    首先创建逻辑卷smit lv ,这里没多大问题就不细述了. 输入要创建的逻辑卷名.所属卷组.分配多少个LP.创建在哪块磁盘上等,另外还可以设置镜像,默认是只有一份镜像的,即不做mirror. 到此LV ...

  4. 【Hello 2018 C】Party Lemonade

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出凑够2^j最少需要花费多少钱. 即试着把第i种物品买2^(j-i)个,看看会不会更便宜 记录在huafei[0..31]中 然 ...

  5. UVALive 5292 Critical Links

    Critical Links Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...

  6. CSUOJ 1554 SG Value

    1554: SG Value Time Limit: 5 Sec  Memory Limit: 256 MBSubmit: 140  Solved: 35 Description The SG val ...

  7. UICollectionView 集合视图 的使用

    直接上代码: // // RootViewController.m // // #import "RootViewController.h" #import "Colle ...

  8. 淘宝的css初始化代码

    ;; } body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; } h1, h2, h3, h ...

  9. jquery模拟可输入的下拉框

    //页面html <div id="select" class="select" > <ul> <c:forEach items= ...

  10. install-软件安装跟push的区别

    今天在做项目的时候,需要往一个user版本的手机中安装一个应用,就在网上查了相应的方法,可以使用如下命令 adb install -r out/target/product/vanzo6752_lwt ...