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

相关文章

电脑提示xlstat4.dll丢失怎么修复? xlstat4.dll文件丢失处理办法

《电脑提示xlstat4.dll丢失怎么修复?xlstat4.dll文件丢失处理办法》长时间使用电脑,大家多少都会遇到类似dll文件丢失的情况,不过,解决这一问题其实并不复杂,下面我们就来看看xls... 在Windows操作系统中,xlstat4.dll是一个重要的动态链接库文件,通常用于支持各种应用程序

SQL Server数据库死锁处理超详细攻略

《SQLServer数据库死锁处理超详细攻略》SQLServer作为主流数据库管理系统,在高并发场景下可能面临死锁问题,影响系统性能和稳定性,这篇文章主要给大家介绍了关于SQLServer数据库死... 目录一、引言二、查询 Sqlserver 中造成死锁的 SPID三、用内置函数查询执行信息1. sp_w

Java对异常的认识与异常的处理小结

《Java对异常的认识与异常的处理小结》Java程序在运行时可能出现的错误或非正常情况称为异常,下面给大家介绍Java对异常的认识与异常的处理,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参... 目录一、认识异常与异常类型。二、异常的处理三、总结 一、认识异常与异常类型。(1)简单定义-什么是

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

python判断文件是否存在常用的几种方式

《python判断文件是否存在常用的几种方式》在Python中我们在读写文件之前,首先要做的事情就是判断文件是否存在,否则很容易发生错误的情况,:本文主要介绍python判断文件是否存在常用的几种... 目录1. 使用 os.path.exists()2. 使用 os.path.isfile()3. 使用

Java中Map.Entry()含义及方法使用代码

《Java中Map.Entry()含义及方法使用代码》:本文主要介绍Java中Map.Entry()含义及方法使用的相关资料,Map.Entry是Java中Map的静态内部接口,用于表示键值对,其... 目录前言 Map.Entry作用核心方法常见使用场景1. 遍历 Map 的所有键值对2. 直接修改 Ma

Golang 日志处理和正则处理的操作方法

《Golang日志处理和正则处理的操作方法》:本文主要介绍Golang日志处理和正则处理的操作方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录1、logx日志处理1.1、logx简介1.2、日志初始化与配置1.3、常用方法1.4、配合defer

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

深入解析 Java Future 类及代码示例

《深入解析JavaFuture类及代码示例》JavaFuture是java.util.concurrent包中用于表示异步计算结果的核心接口,下面给大家介绍JavaFuture类及实例代码,感兴... 目录一、Future 类概述二、核心工作机制代码示例执行流程2. 状态机模型3. 核心方法解析行为总结:三

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061