参考文章:

Android滑动到顶部悬停

NestedScrollView的使用

效果图:

实现步骤:

    1. 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
    2. 将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
    3. 给滚动的NestedScroolView设置
      app:layout_behavior="@String/appbar_scrolling_view_behavior"
      就大功告成了(记得根布局要是CoordinatorLayout)
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.administrator.scroll4.MainActivity"> <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="220dp"
app:contentScrim="#000000"
app:layout_scrollFlags="scroll"> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#987545"
android:gravity="center"
android:text="banner区域"
android:textColor="#ffffff" />
</android.support.design.widget.CollapsingToolbarLayout> <TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
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"> <com.example.administrator.scroll4.MyListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView; /**
* Created by Administrator on 2017/5/5.
*/
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
} public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} @Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
} }
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter; import java.util.ArrayList;
import java.util.List; public class MainActivity extends AppCompatActivity { private MyListView lv;
private List<String> list; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); lv = (MyListView) findViewById(R.id.lv);
list = new ArrayList<>();
for (int i = 0; i < 100; i++) {
list.add(i + "");
}
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}
}

NestedScrollView的更多相关文章

  1. NestedScrollView嵌套RecycleView 滑动 实现上滑隐藏 下滑显示头部效果

    废了好大的劲才弄好的,记下来 方便以后查看 public class MainActivity extends AppCompatActivity { private RecyclerView mRe ...

  2. NestedScrollView嵌套ViewPager

    NestedScrollView嵌套ViewPager 效果图 重写ViewPager package com.kongqw.kbox.view; import android.content.Con ...

  3. Android开发 解决EditText与NestedScrollView 滚动冲突问题

    问题简述 在将EditText套进NestedScrollView的情况下,EditText输入了多行内容后,无法触摸滚动到第一行 问题原因 在将EditText套进NestedScrollView的 ...

  4. NestedScrollView嵌套ListView时只显示一行的解决方法

    在使用CoordinatorLayout和AppBarLayout实现嵌套滑动的时候,出现listview没有嵌套滑动: 如果要实现嵌套滑动,则需要添加NestedScrollView,但是结果发现l ...

  5. 使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突

    使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种冲突 如果你还在为处理滑动冲突而发愁,那么你需要静 ...

  6. Android 解决NestedScrollView 嵌套 RecyclerView出现的卡顿,上拉刷新无效

    解决卡顿的方法最简单的就是设置RecyclerView的android:nestedScrollingEnabled="false",放弃自己的滑动,交给外部的NestedScro ...

  7. NestedScrollView,RecyclerView

    为什么把它们放一起呢, 是因为它有着相同的特点 在新版的support-v4兼容包里面有一个NestedScrollView控件,这个控件其实和普通的ScrollView并没有多大的区别,这个控件其实 ...

  8. NestedScrollView嵌套RecyclerView

    天气渐寒,然学习不可懈怠,记录一下使用NestedScrollView嵌套RecyclerView的两个问题,以后遇到可以来这里温故. 应该说在MD中,RecyclerView代替了ListView, ...

  9. Android NestedScrollView与RecyclerView嵌套,以及NestedScrollView不会滚动到屏幕顶部解决

    ①NestedScrollView与RecyclerView嵌套,导致滚动惯性消失 解决:mRecyclerView.setNestedScrollingEnabled(false); ②Nested ...

随机推荐

  1. 可能是国内最火的开源项目 —— C/C++ 篇

    程序员们,在北上广你还能买房吗? >>>   推荐阅读: 可能是最火的开源项目 -- Java 篇 可能是国内最火的开源项目 -- PHP 篇 可能是国内最火的开源项目 -- Pyt ...

  2. Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0 异常处理

    在本机开发asp.net .rdlc报表后,部署到本地没有问题. 当把网站发布后部署在IIS上,新电脑上(只安装了.net framwork4.5),提示如下错误: “Could not load f ...

  3. 汕头市队赛SRM 20 T2不净的圣杯

    不净的圣杯 SRM 20 背景 作为一张BUG级别的卡,官方打算把它修改得人畜无害一些…… 虽然名字还没想好,但是能力大概是对敌方所有单位造成d点伤害,d为自己牌组中所有卡的编号的最大公约数.这无疑是 ...

  4. SSH ERROR: Too many Authentication Failures

    来自: How to recover from "Too many Authentication Failures for user root" 其中一种可以解决的方式 eval ...

  5. vue装逼神器简述

    主要是分享下用vuejs开发项目过程中遇到的问题,vuejs开发的优势和需要注意的地方. 项目主要页面:主页,最新,分类,分类列表,详情页,结果页,斗图(列表,制作页) 效果图: 地址:https:/ ...

  6. PHP序列化、反序列化常用的魔术方法

    __wakeup() //使用unserialize时触发__sleep() //使用serialize时触发__destruct() //对象被销毁时触发__call() //在对象上下文中调用不可 ...

  7. python科学计算整理

    网站: http://bokeh.pydata.org/gallery.html

  8. 很重要的处理项目url[www]

    http://www.xdowns.com/soft/10/57/2013/Soft_113319.html https://github.com/TricksterGuy/Morphan http: ...

  9. python爬虫模块之URL管理器模块

    URL管理器模块 一般是用来维护爬取的url和未爬取的url已经新添加的url的,如果队列中已经存在了当前爬取的url了就不需要再重复爬取了,另外防止造成一个死循环.举个例子 我爬www.baidu. ...

  10. Makefile系列之四 :条件判断

    一.示例 下面的例子,判断$(CC)变量是否“gcc”,如果是的话,则使用GNU函数编译目标. libs_for_gcc = -lgnu normal_libs = foo: $(objects) i ...