CoordinatorLayout的简单使用

CoordinatorLayout动态设置内容有多少就只能滚多少 前言 大家有没有遇到这样的情况,CoordinatorLayout + 列表(RecyclerView也好,其他控件也好)。当你的列表只有一两条数据的时候,你的产品或UI就会问你,为什么数据这么少,你还让它滚一屏的高度。 没错,使用CoordinatorLayout + AppbarLayout这一套组合,实现折叠效果的时候,RecyclerView也好,NestedScrollView也好,ViewPager也好,加了 这个behavior(@string/appbar_scrolling_view 阅读详情

这种折叠式的效果,感觉确实挺不错的,抽点时间,看了几篇文章,整理一下,这里主要就是整理了一个CoordinatorLayout+AppBarLayout+TabLayout的简单用法Demo。关于更多用法后期再细看吧~
其实主要就是布局设置一些行为就行了:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.youth.banner.Banner
            android:id="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            app:layout_scrollFlags="scroll|enterAlways"/>
        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabBackground="@android:color/transparent" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

外出布局就用CoordinatorLayout就好了,里层套一个AppBarLayout。这里我把AppBarLayout看成是一个垂直方向的LinearLayout。demo里也结合了一个轮播图。
轮播图设置了属性:

app:layout_scrollFlags="scroll|enterAlways"

scroll用法:大体意思就是当该View滑到顶部的时候,不会停留,会继续划出屏幕。
enterAlways用法:大体意思就是当往回滑动时,会立刻先显示出该View。如果不写的话,就只有当屏幕滑动到最底的时候,该View才会跟随显示出来。
viewPager主要增加的属性:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

ViewPager当然就是跟TabLayout联动了,ok了~大概用法就是这样了,具体Demo代码也不放了,很简单。

CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决 阅读详情

相关推荐

Android的CoordinatorLayout简单使用

请原谅直接用真实项目做gif,写这篇文章主要是怕自己忘记,如果能帮到你实属荣幸。先看效果图:实现很简单,主要用到了CoordinatorLayout,AppBarLayout,RecyclerView。RecyclerView其实就是listview,网上很多讲解,注意这只能用RecyclerView才有效果。首先导入依赖:compile 'com.android.support:design:2...

l18203612341的博客 698

Qt设置鼠标追踪setMouseTracking()

Qt设置鼠标追踪setMouseTracking() void setMouseTracking(bool enable)参数可以为true或者false,若将参数置为false,意味着关闭鼠标追踪,此时只有当至少一个鼠标按键按下时才能捕获到鼠标移动事件。而将参数置为true时,即使没有按下鼠标键,移动鼠标时也可以捕获鼠标的移动事件。 ...

Goallegoal的博客 2125

CoordinateLayoutDemo:Android CoordinatorLayout的一项测试

CoordinateLayoutDemo 杂弹枪

CoordinatorLayoutDemo: Android设计之美的实现

CoordinatorLayoutDemo: Android设计之美的实现 在Android开发中,对于界面的布局和交互设计,Google提出了一个强大的工具——CoordinatorLayout。这个库为开发者提供了优雅的方式去构建高度动态和响应式的用户界面。现在,让我们一起深入了解一下开源的CoordinatorLayoutDemo项目,看看它如何帮助我们更好地理解和运用这个设计模式。 项目简...

gitblog_00097的博客 500

CoordinatorLayout使用,仿招商银行8.1全部菜单布局

Android CoordinatorLayout(协调者布局)使用Demo,demo5仿招商银行8.1全部菜单布局

【GD32F407】i2c主机发送,从机中断接收

前言 现在手里负责的一个项目需要用i2c和主芯片进行通信主动发送,中断接收,这就需要支持i2c主机模式和从机模式,先查看原理图 这里我们用到了两条i2c总线进行数据的交替传输,避免在使用一条总线是发送数据和接收数据冲突 初始化i2c控制器 s32_k i2cDevInit(u8 byBusId, TI2cBus *pTI2cBus) { //PCLK = 36000000 BOOL retFlg = FALSE; int I2xSCL = pTI2cBus->byFastMode ?

Enosji的博客 6246

CoordinatorLayout的使用如此简单

https://blog.youkuaiyun.com/huachao1001/article/details/51554608 曾在网上找了一些关于CoordinatorLayout的教程,大部分文章都是把CoordinatorLayout、AppbarLayout、CollapsingToolbarLayout 以及Toolbar等一起使用来介绍,这让我不知不觉在心中认为把这几个布局要一起使用,而且只是用于那种场景中。其实CoordinatorLayout的功能并不是局限于与AppBarLayout一起使用,它的功

az44yao的专栏 191

Windows 11 的C盘User(用户)文件夹下的用户文件夹名称的修改

背景介绍:由于系统重装导致Windows 11的系统用户名与C盘User(用户)文件夹下的用户名文件夹(公用文件夹旁边的文件夹)出现名称不一致,事例中系统用户名命名为“寂萧”,User(用户)文件夹下的文件夹名称却是“77555”。【QQ邮箱前五位真的真的看着很别扭】注:改名有风险,三思而后行。User(用户)文件夹下的用户名是中文在某些软件的应用场景下产生不便,导致很多软件莫名其妙报错,甚至无法使用,笔者不建议修改为中文名。//和笔者一样的强迫症除外//

2302_79084172的博客 10万+

CoordinatorLayout 简单使用

CoordinatorLayout:协调者布局,用来组织内部的子view之间的协作的一个view。他其实是一个FrameLayout,它的布局方式默认是层层叠加的。 1.实现Toolbar隐藏效果 实现隐藏Toolbar,在Toolbar里添加属性: app:layout_scrollFlags=“scroll|enterAlways” <?xml version="1.0" encodin...

Chents 518

用UDP协议在dos命令行里模拟一个聊天程序

/* 需求: 在dos命令行里模拟一个聊天程序 有收数据的部分,和发数据的部分,这两部分需要同时执行。 那就需要用到多线程技术。 一个线程控制收,一个线程控制发。 */ import java.io.*; import java.net.*; class C

s_x_x的记录 1955

『Apisix进阶(九)』基于Upstream实现服务转发的最佳实践

本篇文章将以服务转发为核心,带你从原理到实战,深入了解 Upstream 的配置方法与常用场景。

老陈聊架构 1515

Android RecyclerView与CoordinatorLayout联合实现简单的折叠布局

Recycler 与 CoordinatorLayout配合使用 在我们的日常工作中,用到折叠布局的时候一般都是配合RecyclerView使用,或者直接使用Scroll控件,这篇文章就是简单的实现折叠布局,完全解析请移步:CoordinatorLayout 完全解析 本文章也是参考此文章。 引入依赖 理论上是不需要引入任何依赖的因为Google会自带,不过还是在这里贴一条,CoordinatorLayout是AndroidX里面的Material包内的,引入方法为添加下列依赖 implementation

小傲傲的博客 1569

【CASS精品教程】013:CASS9.1生成标准图幅案例教程

在CASS中,可以很方便的生成标准图幅,如50*50。本文演示cass中,根据测区范围标准图幅生成过程。

智慧空间实验室 1万+

CoordinatorLayout的最简单使用

分析:案例当我们在屏幕中拖动一个方块运动时候,想让另外一个方块与其保持相同的位置关系的时候 以前我们的方式是 监听蓝色方块的移动然后将位置赋值给红色的方块,而现在不用,我们只需要给红色方块进行位置赋值就可以了 &lt;android.support.design.widget.FloatingActionButton android:src="@drawabl...

afdasfggasdf的博客 463

芒果YOLO11改进59:分类损失函数Loss篇FocalLoss:即插即用|最新改进FocalLoss损失函数,提高处理不平衡数据分类场景下的任务性能,提升YOLO11检测精度

即插即用|最新改进FocalLoss损失函数,提高处理不平衡数据分类场景下的任务性能,提升YOLO11检测精度

包括YOLOv5、YOLOv7、YOLOv8等模型改进 550

[Python图像处理] 十九.图像分割之基于K-Means聚类的区域分割

前面的文章讲解了图像锐化和边缘提取技术,该篇文章将开始围绕图像分割进行讲解。图像分割就是把图像分成若干个特定的、具有独特性质的区域并提出感兴趣目标的技术和过程。 本篇文章主要讲解基于理论的图像分割方法,通过K-Means聚类算法实现图像分割或颜色分层处理。基础性文章,希望对你有所帮助。 1.K-Means原理 2.K-Means聚类分割灰度图像 3.K-Means聚类对比分割彩色图像

杨秀璋的专栏 4万+

CoordinatorLayout布局的简单实用

1、首先导入依赖 compile 'com.android.support:design:22.2.1' 2、CoordinatorLayout能做什么 在学习CoordinatorLayout之前,很有必要了解CoordinatorLayout能帮我们做什么,从名字上可以看出,就是帮我们协调子View的。 怎么个协调法呢?就是它根据我们的定制,帮助我们协调各

luanxuye的博客 861

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 视频播放
下一篇: 使用友盟实现第三方登录和分享
尘彦
博客等级 码龄11年 92粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尘彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值