CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+ViewPager滑动效果,以及代码处理是否推动效果

本文主要是介绍CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+ViewPager滑动效果,以及代码处理是否推动效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

布局文件

<?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:id="@+id/activity_video_detail"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="exle.li_yuweii.superapp.activitys.VideoDetailActivity"><android.support.design.widget.AppBarLayout
        android:fitsSystemWindows="true"android:id="@+id/video_detail_appbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#ffff"app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><!--可以收放 ToolBar的布局--><!--设置标题需要调用CollapsingToolbarLayout的 setTitle--><!--使用ContentScrim 可以指定颜色 图片 当收起来的时候,切换成指定的内容--><!--scrimVisibleHeightTrigger当收起多少距离的时候显示contentScrim--><android.support.design.widget.CollapsingToolbarLayout
            android:fitsSystemWindows="true"android:id="@+id/video_detail_collapsing"android:layout_width="match_parent"android:layout_height="200dp"app:contentScrim="#FB7299"app:layout_scrollFlags="scroll|exitUntilCollapsed"><!--app:scrimVisibleHeightTrigger="50dp"--><FrameLayout
                android:id="@+id/video_detail_fragment"android:layout_width="match_parent"android:layout_height="wrap_content"><SurfaceView
                    android:id="@+id/video_detail_surface_view"android:layout_width="match_parent"android:layout_height="200dp"android:visibility="invisible" /><LinearLayout
                    android:id="@+id/video_detail_play_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom"android:background="#9999"android:gravity="center_vertical"android:orientation="horizontal"android:visibility="invisible"><ImageView
                        android:id="@+id/video_controller_play"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@android:drawable/ic_media_pause" /><SeekBar
                        android:id="@+id/video_controller_progress"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1" /><TextView
                        android:id="@+id/video_controller_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="00:00" /><ImageView
                        android:id="@+id/video_controller_orientation_switch"android:layout_width="20dp"android:layout_height="20dp"android:paddingLeft="3dp"android:src="@drawable/change" /></LinearLayout></FrameLayout><ImageView
                android:fitsSystemWindows="true"android:id="@+id/video_detail_cover"android:layout_width="match_parent"android:layout_height="wrap_content"android:adjustViewBounds="true"android:scaleType="fitXY" /><!--app:layout_collapseMode="parallax" />--><android.support.v7.widget.Toolbar
                android:id="@+id/video_detail_tool_bar"android:layout_width="match_parent"android:layout_height="?actionBarSize"app:layout_collapseMode="pin"><ImageView
                    android:id="@+id/video_detail_iamge1"android:src="@drawable/action_button_back_pressed_light"android:layout_width="wrap_content"android:layout_height="22dp" /><LinearLayout
                    android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><TextView
                        android:id="@+id/video_detail_text1"android:text="SuperApp"android:gravity="center"android:layout_width="wrap_content"android:layout_height="match_parent" /><ImageView
                        android:id="@+id/video_detail_image"android:src="@drawable/ic_tv_play"android:adjustViewBounds="true"android:visibility="invisible"android:layout_width="wrap_content"android:layout_gravity="center"android:layout_height="22dp" /><TextView
                        android:id="@+id/video_detail_text"android:visibility="invisible"android:text="立即播放"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout></android.support.v7.widget.Toolbar></android.support.design.widget.CollapsingToolbarLayout><!--Tab 简介和评论--></android.support.design.widget.AppBarLayout><android.support.design.widget.FloatingActionButton
        android:id="@+id/video_detail_play_fab"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginRight="16dp"app:layout_anchor="@id/video_detail_appbar"app:layout_anchorGravity="right|bottom" /><!--layut_behavior 用于处理 当前控件滚动的时候,怎么处理其他控件--><!--TODO:检查在ViewPager中使用,能否滚动Toolbar--><LinearLayout
        android:id="@+id/video_detail_linear_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"app:layout_behavior="@string/appbar_scrolling_view_behavior"><android.support.design.widget.TabLayout
            android:id="@+id/video_detail_tab_layout"android:layout_width="150dp"android:layout_height="wrap_content"app:tabSelectedTextColor="@color/topColor"app:layout_behavior="@string/appbar_scrolling_view_behavior"android:layout_gravity="bottom"app:tabTextColor="#000"/><android.support.v4.view.ViewPager
            android:id="@+id/video_detail_view_pager"android:layout_width="match_parent"android:layout_height="match_parent"android:overScrollMode="never" /></LinearLayout><!--<android.support.v4.widget.NestedScrollView--><!--android:layout_width="match_parent"--><!--android:layout_height="match_parent"--><!--app:layout_behavior="@string/appbar_scrolling_view_behavior">--><!--<LinearLayout--><!--android:layout_width="match_parent"--><!--android:layout_height="match_parent"--><!--android:orientation="vertical">--><!--</LinearLayout>--><!--</android.support.v4.widget.NestedScrollView>--></android.support.design.widget.CoordinatorLayout>
  app:layout_scrollFlags="scroll|exitUntilCollapsed"

这个设置推到上边toolbar在上边保留

  android:fitsSystemWindows="true"

这个设置沉浸效果设置顶部状态栏时

app:layout_anchor="@id/video_detail_appbar"

FloatingActionButton必须绑定到AppBar上才可以推上去消失

 app:layout_behavior="@string/appbar_scrolling_view_behavior"

AppBar下方的控件要设置这个属性才可以联动

代码里设置推动效果

//设置不可推动layoutParams = (AppBarLayout.LayoutParams) collapsing.getLayoutParams();int scrollFlags = layoutParams.getScrollFlags(); layoutParams.setScrollFlags(0);
//设置可以推动
layoutParams = (AppBarLayout.LayoutParams) collapsing.getLayoutParams();layoutParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);collapsing.setLayoutParams(layoutParams);//这句必须加上

这篇关于CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+ViewPager滑动效果,以及代码处理是否推动效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/538984

相关文章

Python进行JSON和Excel文件转换处理指南

《Python进行JSON和Excel文件转换处理指南》在数据交换与系统集成中,JSON与Excel是两种极为常见的数据格式,本文将介绍如何使用Python实现将JSON转换为格式化的Excel文件,... 目录将 jsON 导入为格式化 Excel将 Excel 导出为结构化 JSON处理嵌套 JSON:

Spring Boot 中的默认异常处理机制及执行流程

《SpringBoot中的默认异常处理机制及执行流程》SpringBoot内置BasicErrorController,自动处理异常并生成HTML/JSON响应,支持自定义错误路径、配置及扩展,如... 目录Spring Boot 异常处理机制详解默认错误页面功能自动异常转换机制错误属性配置选项默认错误处理

SpringBoot 异常处理/自定义格式校验的问题实例详解

《SpringBoot异常处理/自定义格式校验的问题实例详解》文章探讨SpringBoot中自定义注解校验问题,区分参数级与类级约束触发的异常类型,建议通过@RestControllerAdvice... 目录1. 问题简要描述2. 异常触发1) 参数级别约束2) 类级别约束3. 异常处理1) 字段级别约束

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

Java堆转储文件之1.6G大文件处理完整指南

《Java堆转储文件之1.6G大文件处理完整指南》堆转储文件是优化、分析内存消耗的重要工具,:本文主要介绍Java堆转储文件之1.6G大文件处理的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言文件为什么这么大?如何处理这个文件?分析文件内容(推荐)删除文件(如果不需要)查看错误来源如何避

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

Java docx4j高效处理Word文档的实战指南

《Javadocx4j高效处理Word文档的实战指南》对于需要在Java应用程序中生成、修改或处理Word文档的开发者来说,docx4j是一个强大而专业的选择,下面我们就来看看docx4j的具体使用... 目录引言一、环境准备与基础配置1.1 Maven依赖配置1.2 初始化测试类二、增强版文档操作示例2.

MyBatis-Plus通用中等、大量数据分批查询和处理方法

《MyBatis-Plus通用中等、大量数据分批查询和处理方法》文章介绍MyBatis-Plus分页查询处理,通过函数式接口与Lambda表达式实现通用逻辑,方法抽象但功能强大,建议扩展分批处理及流式... 目录函数式接口获取分页数据接口数据处理接口通用逻辑工具类使用方法简单查询自定义查询方法总结函数式接口

SpringBoot结合Docker进行容器化处理指南

《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与