NestedScrollView
参考文章:
Android滑动到顶部悬停
NestedScrollView的使用
效果图:

实现步骤:
- 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLayout之内
- 将CollapsingToolbarLayout的app:layout_scrollFlags设置为scroll
- 给滚动的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的更多相关文章
- NestedScrollView嵌套RecycleView 滑动 实现上滑隐藏 下滑显示头部效果
废了好大的劲才弄好的,记下来 方便以后查看 public class MainActivity extends AppCompatActivity { private RecyclerView mRe ...
- NestedScrollView嵌套ViewPager
NestedScrollView嵌套ViewPager 效果图 重写ViewPager package com.kongqw.kbox.view; import android.content.Con ...
- Android开发 解决EditText与NestedScrollView 滚动冲突问题
问题简述 在将EditText套进NestedScrollView的情况下,EditText输入了多行内容后,无法触摸滚动到第一行 问题原因 在将EditText套进NestedScrollView的 ...
- NestedScrollView嵌套ListView时只显示一行的解决方法
在使用CoordinatorLayout和AppBarLayout实现嵌套滑动的时候,出现listview没有嵌套滑动: 如果要实现嵌套滑动,则需要添加NestedScrollView,但是结果发现l ...
- 使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突
使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种冲突 如果你还在为处理滑动冲突而发愁,那么你需要静 ...
- Android 解决NestedScrollView 嵌套 RecyclerView出现的卡顿,上拉刷新无效
解决卡顿的方法最简单的就是设置RecyclerView的android:nestedScrollingEnabled="false",放弃自己的滑动,交给外部的NestedScro ...
- NestedScrollView,RecyclerView
为什么把它们放一起呢, 是因为它有着相同的特点 在新版的support-v4兼容包里面有一个NestedScrollView控件,这个控件其实和普通的ScrollView并没有多大的区别,这个控件其实 ...
- NestedScrollView嵌套RecyclerView
天气渐寒,然学习不可懈怠,记录一下使用NestedScrollView嵌套RecyclerView的两个问题,以后遇到可以来这里温故. 应该说在MD中,RecyclerView代替了ListView, ...
- Android NestedScrollView与RecyclerView嵌套,以及NestedScrollView不会滚动到屏幕顶部解决
①NestedScrollView与RecyclerView嵌套,导致滚动惯性消失 解决:mRecyclerView.setNestedScrollingEnabled(false); ②Nested ...
随机推荐
- 如何在阿里云服务器部署Django
这段时间一直在搞我的网站——大学易,一个大学生评课网站,主要是提供课程的详尽信息(比如老师会不会经常点名,有没有期中考试),课程资料的下载等等. 这篇文章主要是分享给那些菜鸟,就是像我一样完全没有搞过 ...
- Independence.
It's not giving up, it's letting go, and moving to a better place. I will survive and be the one who ...
- linux时区修定转
https://blog.csdn.net/feng12345zi/article/details/80348501
- redis启动脚本
#!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the ...
- CAS单点登录原理
转自 https://www.cnblogs.com/lihuidu/p/6495247.html 1.基于Cookie的单点登录的回顾 基于Cookie的单点登录核心原理: 将用户名密 ...
- vue-route-transition路由前进后退动画
vue-route-transition vue router 切换动画 特性 模拟前进后退动画 基于css3流畅动画 基于sessionStorage,页面刷新不影响路由记录 路由懒加载,返回可记录 ...
- Docker explainations
What does docker run --link mean, what's the usage? link 是在两个contain之间建立一种父子关系,父container中的web,可以得到子 ...
- 对于所有对象都通用方法的解读(Effective Java 第三章)
这篇博文主要介绍覆盖Object中的方法要注意的事项以及Comparable.compareTo()方法. 一.谨慎覆盖equals()方法 其实平时很少要用到覆盖equals方法的情况,没有什么特殊 ...
- python中的Queue模块
queue介绍 queue是python的标准库,俗称队列.可以直接import引用,在python2.x中,模块名为Queue.python3直接queue即可 在python中,多个线程之间的数据 ...
- linux平台学x86汇编语言学习集合帖
linux平台学x86汇编语言学习集合帖 linux平台学x86汇编(一):https://blog.csdn.net/shallnet/article/details/45543237 linux平 ...