【Android+Kotlin】NestedScrollView
扉:
- 找了蛮多帖子感觉不是很友好,找到了一个帖子并升级了androidx
- 这个帖子不错
- AppBarLayout与沉浸式布局好看
- CollapsingToolLayout可折叠工具栏
- 下载地址
1. 效果图
- 上面是banner区域
- 向下拖动到一定程度图片会变暗幕
- 固定中间的悬浮部分 下侧RecycleView正常滑动
2. 上代码
1. XML
- 注意事项
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"?>
<androidx.coordinatorlayout.widget.CoordinatorLayoutxmlns: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=".MainActivity"><com.google.android.material.appbar.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><com.google.android.material.appbar.CollapsingToolbarLayoutandroid:layout_width="match_parent"android:layout_height="220dp"app:contentScrim="#000000"app:layout_scrollFlags="scroll"><androidx.appcompat.widget.AppCompatImageViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/banner"/><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="banner区域"android:textColor="#000000" /></com.google.android.material.appbar.CollapsingToolbarLayout><TextViewandroid:layout_width="match_parent"android:layout_height="30dp"android:gravity="center"android:text="悬浮的部分" /></com.google.android.material.appbar.AppBarLayout><androidx.core.widget.NestedScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior"><com.ywjh.nestedscrollview.MyListViewandroid:id="@+id/lv"android:layout_width="match_parent"android:layout_height="match_parent" /></androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
2. MyListView
package com.ywjh.nestedscrollviewimport android.content.Context
import android.util.AttributeSet
import android.widget.ListViewclass MyListView : ListView {constructor(context: Context?) : super(context) {}constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context,attrs,defStyleAttr) {}public override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {val expandSpec = MeasureSpec.makeMeasureSpec(Int.MAX_VALUE shr 2,MeasureSpec.AT_MOST)super.onMeasure(widthMeasureSpec, expandSpec)}
}
3. MAC
package com.ywjh.nestedscrollviewimport android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import androidx.appcompat.app.AppCompatActivity
import java.util.*class MainActivity : AppCompatActivity() {private var lv: MyListView? = nullprivate var list: MutableList<String?>? = nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)lv = findViewById<View>(R.id.lv) as MyListViewlist = ArrayList()for (i in 0..99) {list?.add(i.toString() + "")}val adapter: ArrayAdapter<*> =ArrayAdapter<Any?>(this, android.R.layout.simple_list_item_1,list as ArrayList<String?> as List<Any?>)lv!!.adapter = adapter}
}
【Android+Kotlin】NestedScrollView相关推荐
- 【Android+Kotlin】自适应CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout与Palette
参考文档 CoordinatorLayout 完全解析 1.1 关于NestedScrollingParent2.NestedScrollingChild2接口目的 支持滑动嵌套类的父布局 这篇文的d ...
- 【Android,Kotlin】No type arguments expected for class Call
No type arguments expected for class Call 又又又出现的问题 当我们使用retrofit范型错误会报如上问题 针对如上问题,我找到了出现相同问题的解决方案 链接 ...
- 【Android 文件管理】分区存储 ( 修改与删除图片文件 )
文章目录 一.分区存储模式下使用 MediaStore 修改图片 二.分区存储模式下使用 MediaStore 删除图片 三.相关文档资料 Android 分区存储系列博客 : [Android 文件 ...
- 【Android 文件管理】分区存储 ( 创建与查询图片文件 )
文章目录 一.分区存储模式下使用 MediaStore 插入图片 二.分区存储模式下使用 MediaStore 查询图片 三.相关文档资料 Android 分区存储系列博客 : [Android 文件 ...
- 【Android APT】编译时技术 ( 编译时注解 和 注解处理器 依赖库 )
文章目录 一.编译时注解和注解处理器 二.创建 编译时注解 和 注解处理器 三.添加 编译时注解 和 注解处理器 依赖库依赖 四.博客资源 一.编译时注解和注解处理器 上一篇博客 [Android A ...
- 【Android 文件管理】分区存储 ( MediaStore 文件操作 )
文章目录 一.动态权限申请 二.MediaStore 操作文件 三.完整代码示例 1.MainActivity 核心代码 2.build.gradle 构建脚本 3.清单文件 五.相关文档资料 特别注 ...
- 【Android 安全】DEX 加密 ( 代理 Application 开发 | 项目中配置 OpenSSL 开源库 | 使用 OpenSSL 开源库解密 dex 文件 )
文章目录 一.项目中配置 OpenSSL 开源库 二.OpenSSL 开源库解密参考代码 三.解密 dex 文件的 Java 代码 四.解密 dex 文件的 Jni 代码 参考博客 : [Androi ...
- 【Android 安全】DEX 加密 ( 代理 Application 开发 | 交叉编译 OpenSSL 开源库 )
文章目录 一.OpenSSL 开源库简介 二.OpenSSL 源码及环境变量脚本下载 三.修改环境变量脚本 四.OpenSSL 交叉编译 五.OpenSSL 交叉编译相关资源下载 参考博客 : [An ...
- 【Android 安全】DEX 加密 ( Java 工具开发 | apk 文件签名 )
文章目录 一.生成 jks 文件 二.签名命令 三.执行结果 四.处理 Unsupported major.minor version 52.0 错误 参考博客 : [Android 安全]DEX 加 ...
最新文章
- Java基础:JDK1.5新特性
- 线性稀疏自编码机_特征工程之特征缩放amp;特征编码
- 解决iIntelliJ IDEA中新建servlet后,报错cannot resolve symbol ‘HttpServletRequest‘的问题
- 从MVP到微软产品经理的几点心得
- linux gcc 简单使用记录01
- linux 脚本 数字运算符,Shell 基本运算符
- 网络测试工具 - QCheck
- codeM 2018 资格赛
- C51寄存器详解(Reg51.h)
- 如何用虚拟机安装服务器系统教程,手把手教你虚拟机如何安装系统
- EasyUI框架介绍
- 数据挖掘案例:建立客户流失模型
- 惠普打印机驱动下载安装后不能使用,驱动人生解决方案
- PHP繁體,php如何实现转繁体
- 阿里巴巴都害怕的区块链电商到底是什么?
- win10你的设备遇到问题,需要重启的五种解决方法
- 《车联网(智能网联汽车)产业发展行动计划》正式发布,车联网产业发展进一步提速...
- 从图灵奖小插曲看50年来什么样的人工智能最受追捧
- 【指针】编写并测试一个函数larger_of(),该函数把两个double类型变量的值替 换为较大的值。例如, larger_of(x, y)会把x和y中较大的值重新赋给两个变 量。
- 【git安装、使用、常用命令】