我自己的xml代码,加上一些理解后的注释

xmlns:tools="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/activity_main"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff"

android:fitsSystemWindows="true">

android:id="@+id/scrollView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff">

android:id="@+id/appBarLayout"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/collapsing_tool_bar_test_ctl"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_scrollFlags="scroll">

android:id="@+id/userScroreRe"

android:layout_width="match_parent"

android:layout_height="240dp"

android:background="#f00">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:id="@+id/radioGroup"

android:layout_width="fill_parent"

android:layout_height="50dip"

android:gravity="center"

android:orientation="horizontal" />

android:id="@+id/myMainScrollView"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:overScrollMode="always"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:id="@+id/mainLinearLayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:layout_width="50dp"

android:layout_height="match_parent"

android:layout_gravity="center"

android:text="测试gem测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测测试测试测试测试测试测试测试测试测试测试测试测试"

/>

需要注意的有几点:

1.CollapsingToolbarLayout必须设置app:layout_scrollFlags=”scroll”,他才可以滑动。

2.NestedScrollView必须设置app:layout_behavior这个属性,他们才会联动。

3.NestedScrollView里面如果嵌套listview等可滑动的布局时要重写listview的onmeasures方法(网上一大堆)。

新项目中仿支付宝的浮动效果

计算距离添加淡入淡出效果

滑动卡顿就当recyclerView滑动到第一个的时候打开appBarLayout

fragment_fish.xml

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/white">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/abl_bar"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

android:layout_width="match_parent"

android:layout_height="@dimen/top_layout_height"

android:background="@color/blue"

android:layout_marginTop="@dimen/tool_bar_height"

app:layout_collapseMode="parallax"

app:layout_collapseParallaxMultiplier="0.7">

android:id="@+id/rl_no_special"

android:layout_width="match_parent"

android:layout_height="@dimen/top_layout_height"

android:orientation="horizontal">

android:id="@+id/rl_top_fish_info"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_centerInParent="true">

android:id="@+id/iv_top_fish_info"

android:layout_width="@dimen/top_layout_icon_width"

android:layout_height="@dimen/top_layout_icon_width"

android:background="@drawable/top_icon_big_fish"

android:layout_gravity="center_horizontal"

android:clickable="true" />

android:id="@+id/tv_top_fish_info"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="鱼塘信息"

android:textColor="@color/white"

android:textSize="@dimen/text_size_middle"

android:layout_gravity="center_horizontal"

android:layout_marginTop="8dp"/>

android:id="@+id/rl_top_device_info"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_centerInParent="true">

android:id="@+id/iv_top_device_info"

android:layout_width="@dimen/top_layout_icon_width"

android:layout_height="@dimen/top_layout_icon_width"

android:background="@drawable/top_icon_device"

android:layout_gravity="center_horizontal"

android:clickable="true"/>

android:id="@+id/tv_top_device_info"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="设备信息"

android:textColor="@color/white"

android:textSize="@dimen/text_size_middle"

android:layout_gravity="center_horizontal"

android:layout_marginTop="8dp"/>

android:id="@+id/rl_top_data_list"

android:layout_width="0dp"

android:layout_weight="1"

android:layout_height="match_parent">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_centerInParent="true">

android:id="@+id/iv_top_data_info"

android:layout_width="@dimen/top_layout_icon_width"

android:layout_height="@dimen/top_layout_icon_width"

android:background="@drawable/top_icon_data"

android:layout_gravity="center_horizontal"

android:clickable="true"/>

android:id="@+id/tv_top_data_info"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="数据列表"

android:textColor="@color/white"

android:textSize="@dimen/text_size_middle"

android:layout_gravity="center_horizontal"

android:layout_marginTop="8dp"/>

android:id="@+id/v_pay_mask"

android:layout_width="match_parent"

android:layout_height="@dimen/top_layout_height"

android:background="@color/transparent" />

android:layout_width="match_parent"

android:layout_height="@dimen/tool_bar_height"

app:layout_collapseMode="pin"

app:contentInsetLeft="0dp"

app:contentInsetStart="0dp">

android:id="@+id/tl_expand"

android:layout_width="match_parent"

android:layout_height="match_parent"

layout="@layout/ele_title_bar"/>

android:id="@+id/tl_collapse"

android:layout_width="match_parent"

android:layout_height="match_parent"

layout="@layout/ele_title_bar_collapse"

android:visibility="gone"/>

android:id="@+id/lv_fish_pond_info"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="10dp"

android:paddingRight="10dp"

android:overScrollMode="never"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

ele_title_bar.xml

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="@dimen/tool_bar_height"

android:background="@color/blue">

android:id="@+id/tv_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="@dimen/tool_bar_title_margin_left"

android:layout_centerVertical="true"

android:text="标题"

android:textColor="@color/white"

android:textSize="@dimen/text_size_big"/>

android:id="@+id/v_expand_mask"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/transparent"/>

ele_title_bar_collapse.xml

android:layout_width="match_parent"

android:layout_height="@dimen/tool_bar_height"

android:background="@color/blue">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

android:id="@+id/iv_top_bar_fish"

android:layout_width="30dp"

android:layout_height="30dp"

android:background="@drawable/top_icon_big_fish"

android:layout_marginLeft="@dimen/tool_bar_title_margin_left"

android:layout_gravity="center_vertical" />

android:id="@+id/iv_top_bar_device"

android:layout_width="30dp"

android:layout_height="30dp"

android:background="@drawable/top_icon_device"

android:layout_marginLeft="@dimen/tool_bar_title_margin_left"

android:layout_gravity="center_vertical" />

android:id="@+id/iv_top_bar_data"

android:layout_width="30dp"

android:layout_height="30dp"

android:background="@drawable/top_icon_data"

android:layout_marginLeft="@dimen/tool_bar_title_margin_left"

android:layout_gravity="center_vertical" />

android:id="@+id/v_collapse_mask"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/transparent"/>

FishFragment.kt

package com.example.administrator.tempdemo.fragment

import android.app.Activity

import android.content.Context

import android.graphics.Color

import android.os.Bundle

import android.support.design.widget.AppBarLayout

import android.support.v4.content.ContextCompat

import android.support.v7.widget.LinearLayoutManager

import android.support.v7.widget.RecyclerView

import android.view.LayoutInflater

import android.view.MotionEvent

import android.view.View

import android.view.ViewGroup

import com.example.administrator.tempdemo.BaseFragment

import com.example.administrator.tempdemo.R

import com.example.administrator.tempdemo.adapter.FishPondInfoAdapter

import com.example.administrator.tempdemo.model.FishPondInfo

import com.example.administrator.tempdemo.presenter.FishPresenter

import com.example.administrator.tempdemo.view.FishView

import com.github.jdsjlzx.ItemDecoration.DividerDecoration

import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter

import com.github.jdsjlzx.recyclerview.ProgressStyle

import kotlinx.android.synthetic.main.ele_title_bar.*

import kotlinx.android.synthetic.main.ele_title_bar_collapse.*

import kotlinx.android.synthetic.main.fragment_fish.*

import org.jetbrains.anko.onClick

import org.jetbrains.anko.onTouch

import org.jetbrains.anko.support.v4.find

import org.jetbrains.anko.support.v4.toast

/**

* Created by Administrator on 2017/6/28.

*/

class FishFragment: BaseFragment(), FishView, AppBarLayout.OnOffsetChangedListener {

lateinit var fishPresenter: FishPresenter

lateinit var fishListener: FishListener

lateinit var fishPondInfoList: MutableList

lateinit var mFishPondInfoAdapter: FishPondInfoAdapter

lateinit var mLRecyclerViewAdapter: LRecyclerViewAdapter

lateinit var layoutManager: LinearLayoutManager

var mMaskColor: Int = 0

interface FishListener{

}

companion object{

fun newInstance(): FishFragment{

return FishFragment()

}

}

override fun onAttach(activity: Activity?) {

super.onAttach(activity)

if(activity is FishListener){

fishListener = activity

}

}

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {

var view = inflater!!.inflate(R.layout.fragment_fish, null)

fishPresenter = FishPresenter(this)

return view

}

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {

super.onViewCreated(view, savedInstanceState)

initView()

initListener()

if(savedInstanceState == null){

this.fishPresenter.loadDataList()

}

}

override fun renderFishPondInfoList(fishPondInfoList: MutableList) {

if(fishPondInfoList != null){

mFishPondInfoAdapter.fishPondInfoList = fishPondInfoList

mLRecyclerViewAdapter.notifyDataSetChanged()

lv_fish_pond_info.refreshComplete(fishPondInfoList.size)

}

}

fun initView(){

mFishPondInfoAdapter = FishPondInfoAdapter(context)

mLRecyclerViewAdapter = LRecyclerViewAdapter(mFishPondInfoAdapter)

tv_title.text = getString(R.string.main_fish)

lv_fish_pond_info.adapter = mLRecyclerViewAdapter

var divider = DividerDecoration.Builder(context)

.setHeight(R.dimen.fish_pond_info_divider)

.setColorResource(R.color.white)

.build()

lv_fish_pond_info.addItemDecoration(divider)

layoutManager = LinearLayoutManager(context)

lv_fish_pond_info.layoutManager = layoutManager

//RecyclerView添加Header

var header = LayoutInflater.from(context).inflate(R.layout.item_fish_now_text_view, activity.findViewById(android.R.id.content) as ViewGroup, false)

mLRecyclerViewAdapter.addHeaderView(header)

//下拉刷新样式

lv_fish_pond_info.setRefreshProgressStyle(ProgressStyle.LineSpinFadeLoader);

lv_fish_pond_info.setArrowImageView(R.drawable.ic_pulltorefresh_arrow);

//禁止上拉加载

lv_fish_pond_info.setLoadMoreEnabled(false)

mMaskColor = ContextCompat.getColor(context, R.color.blue)

abl_bar.addOnOffsetChangedListener(this)

}

fun initListener(){

rl_top_fish_info.onTouch { _, event ->

when(event!!.action){

MotionEvent.ACTION_DOWN -> {

iv_top_fish_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_big_fish_pressed)

tv_top_fish_info.setTextColor(ContextCompat.getColor(activity, R.color.blue_pressed))

}

MotionEvent.ACTION_UP -> {

iv_top_fish_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_big_fish)

tv_top_fish_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

MotionEvent.ACTION_CANCEL -> {

iv_top_fish_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_big_fish)

tv_top_fish_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

}

false

}

rl_top_device_info.onTouch { _, event ->

when(event!!.action){

MotionEvent.ACTION_DOWN -> {

iv_top_device_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_device_pressed)

tv_top_device_info.setTextColor(ContextCompat.getColor(activity, R.color.blue_pressed))

}

MotionEvent.ACTION_UP -> {

iv_top_device_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_device)

tv_top_device_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

MotionEvent.ACTION_CANCEL -> {

iv_top_device_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_device)

tv_top_device_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

}

false

}

rl_top_data_list.onTouch { _, event ->

when(event!!.action){

MotionEvent.ACTION_DOWN -> {

iv_top_data_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_data_pressed)

tv_top_data_info.setTextColor(ContextCompat.getColor(activity, R.color.blue_pressed))

}

MotionEvent.ACTION_UP -> {

iv_top_data_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_data)

tv_top_data_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

MotionEvent.ACTION_CANCEL -> {

iv_top_data_info.background = ContextCompat.getDrawable(activity, R.drawable.top_icon_data)

tv_top_data_info.setTextColor(ContextCompat.getColor(activity, R.color.white))

}

}

false

}

rl_top_fish_info.onClick {

toast("fish")

}

rl_top_device_info.onClick {

toast("device")

}

rl_top_data_list.onClick {

toast("data")

}

//下拉刷新监听

lv_fish_pond_info.setOnRefreshListener {

loadDataList()

}

//RecyclerView滑动监听

lv_fish_pond_info.addOnScrollListener(object: RecyclerView.OnScrollListener(){

override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {

super.onScrollStateChanged(recyclerView, newState)

if (newState == RecyclerView.SCROLL_STATE_IDLE) {

var firstVisiblePosition = layoutManager.findFirstCompletelyVisibleItemPosition();

if (firstVisiblePosition == 0) {

abl_bar.setExpanded(true, true);

}

}

}

})

}

fun loadDataList(){

this.fishPresenter.loadDataList()

}

override fun showLoading() {

}

override fun hideLoading() {

}

override fun context(): Context {

return context.applicationContext

}

override fun onOffsetChanged(appBarLayout: AppBarLayout?, verticalOffset: Int) {

var offset = Math.abs(verticalOffset)

var total = appBarLayout!!.totalScrollRange

var alphaIn = offset

var alphaOut = 0

if((200 - offset) > 0){

alphaOut = 200 - offset

}

var maskColorIn = Color.argb(alphaIn, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor))

var maskColorInDouble = Color.argb(alphaIn*2, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor))

var maskColorOut = Color.argb(alphaOut*2, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor))

if(offset <= total/2){

tl_expand.visibility = View.VISIBLE

tl_collapse.visibility = View.GONE

v_expand_mask.setBackgroundColor(maskColorInDouble)

}else{

tl_expand.visibility = View.GONE

tl_collapse.visibility = View.VISIBLE

v_collapse_mask.setBackgroundColor(maskColorOut)

}

v_pay_mask.setBackgroundColor(maskColorIn)

}

}

完美

好好学习,天天向上。

Potato_zero.jpg

android 置顶窗口位置,Android 滑动悬浮置顶指南相关推荐

  1. android 广告栏效果,叫教你打造一个滑动悬浮置顶的视觉效果,给你的广告栏增加一些特色...

    一个滑动悬浮置顶的View,通过自定义ScrollView来实现一个精美的固定悬浮效果 效果图: 这个特效其实没有那么复杂! 思路: 自定义ListView对头布局进行处理 自定义 RecycleVi ...

  2. android nds模拟器窗口,适用于Android v34的NDS模拟器

    NDS模拟器: Android手机上的NDS模拟器. 因为它处于开发的早期阶段,所以该软件可能会出现一些问题,但这也是一个好的开始. NDS模拟器Dsoid是一款可以在Android上运行Ninten ...

  3. android linux应用安装位置,Android中App安装位置详解

    Android应用可以安装在本机自带存储,同时也可以安装到外部存储(SD卡).自从API 8后也就是Android2.2后,我们能使APK安装到外部存储上.这是一个可选的特性,在工程的manifest ...

  4. android 动画后的位置,Android:Comp之后会重置动画位置

    Android:Comp之后会重置动画位置 我正在使用xml定义的动画将视图滑出屏幕. 问题是,动画完成后,它将立即重置为其原始位置. 我需要知道如何解决这个问题. 这是xml: 这是我用来调用它的J ...

  5. android仿微信发送位置,Android仿微信发送位置-百度地图

    [实例简介] [实例截图] [核心代码] package com.chenxuxu.baiduwechatposition; import android.app.Activity; import a ...

  6. android toast怎么改变位置,Android 更改 Toast 的默认位置方法

    Android中Toast的默认位置在屏幕靠近底部的位置,这个默认位置有时候并不合适.比如页面上内容较少时,内容一般集中在屏幕上半部分,用户的注意力也集中在屏幕上半部分,默认位置的Toast用户可能没 ...

  7. android layout后还原位置,Android图片框架photoview如何记住所有状态并还原,包括缩放度,缩放后的移动的距离等等...

    Android图片框架photoview如何记住状态并还原,包括缩放度,缩放后的移动的距离等等,尝试了好多方法都没有作用. private void generateImages() { for (i ...

  8. android地图获取坐标位置,android 百度地图 根据得到的经纬度 获取位置信息

    满意答案 回复了sfdzyy 2015.07.03 采纳率:57%    等级:7 已帮助:658人 private GeoCoder mSearch = null; // 搜索模块 // 初始化搜索 ...

  9. android 软键盘的从属关系,Android控件属性大全

    控件属性: android属性 Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料, 第一类:属性值为true或false android:layout ...

最新文章

  1. 【转】海量数据相似度计算之simhash和海明距离
  2. IO-1(Java IO、File类)
  3. 【Linux系统编程】线程的基本操作
  4. Java StackTraceElement getClassName()方法与示例
  5. Facebook今年曾多次升级其安全和隐私控制
  6. linux下开启dhcp服务器配置,CentOS下DHCP服务器的配置
  7. 一个vue请求接口渲染页面的例子
  8. sync/atomic 库使用小结
  9. HTML5实践 -- 介绍css3中的几个属性:text-shadow、box-shadow 和 border-radius
  10. js修改IOS微信title
  11. 继承ActionSupport 实现Action与属性驱动传参
  12. petalinux 2020.2 安装教程,基于ubuntu20.04.LTS版本
  13. 位图保存到数据库 VC ado 类
  14. 小白如何打造一个基础的留言板网站(一)
  15. 华为HCNE题库大全(第一部)
  16. 物联网基础设施安全防护
  17. 大型建筑公司如何实现数字化转型
  18. 键盘钢琴(有空进来弹弹琴,真的可以弹的)
  19. maven java archetype_使用Maven Archetype插件构建Maven工程原型模板的实例
  20. 【大数据开发】SparkCore——Spark作业执行流程、RDD编程的两种方式、简单算子

热门文章

  1. web service security profile的设计
  2. How is data replicted from HANA to AS
  3. SAP APF modeler过滤器的设计原理
  4. 如何创建新的SAP CRM middleware subscription
  5. 从popup window出发做navigation
  6. 一个简单的从windows系统往AWS上直接拷贝文件的脚本
  7. SM37作业条目的存储表
  8. SAP CRM 产品主数据和附件(Attachment)的模型关系
  9. 船体6自由度英文名称
  10. 物化视图是否可以exp导出_物化视图导出导入可能导致物化视图日志的失效