Android View动画之LayoutAnimation的使用

接前篇 Android View动画整理 ,本篇介绍 LayoutAnimation 的使用。

参考《安卓开发艺术探索》。

View 动画作用于 View 。
LayoutAnimation 则作用于 ViewGroup , 为 ViewGoup 指定一个动画,ViewGoup 的子 View 出场时就具体动画效果。
简言之,LayoutAnimation 是为 ViewGroup 的子View指定出场动画。

开始使用,两种方式,xml 方式 和 java 方式 。

xml 方式

创建 R/anim/layout_anim_item.xml ,这个是子View的出场动画,实际的动画效果,本例为平移加透明度动画。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:shareInterpolator="true"
    android:interpolator="@android:anim/accelerate_interpolator">

    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"/>

    <translate android:fromXDelta="800" android:toXDelta="0"/>
</set>

定义 LayoutAnimation ,创建 R/anim/layout_anim.xml ,

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:animationOrder="normal"
    android:delay="0.5"
    android:animation="@anim/layout_anim_item">
</layoutAnimation>
  • android:animationOrder :子 View 动画的顺序,可选 normal 、reverse 、random 。normal 是排在前面的子View先开始动画;reverse 是排在后面的子View先开始动画;random 是子View随机播放动画。

  • android:delay :子View 开始动画的时间延迟。源码里的说明 child animation delay = child index * delay * animation duration ,即 1000 毫秒的动画,第1个子View 延迟 500 毫秒(1 * 0.5 * 1000)播放入场动画,第2个子View 延迟 1000 毫秒(2 * 0.5 * 1000)播放入场动画。

  • android:animation :指定子View的出场动画,实际的动画效果。

为 ViewGoup 的指定 android:layoutAnimation 属性,如

<LinearLayout
        <!-- -->
        android:layoutAnimation="@anim/layout_anim"
        <!-- --> >

贴下本例的 xml ,是一个 LinearLayout 包含多个其他控件,

<LinearLayout
        android:id="@+id/ll_layout_anim"
        android:layout_width="400dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:orientation="vertical"
        android:layoutAnimation="@anim/layout_anim"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.129">

        <TextView
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView1"
            android:textColor="@color/my_red"/>

        <TextView
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView2"
            android:textColor="@color/purple_500"/>

        <TextView
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView3"
            android:textColor="@color/black"/>

        <TextView
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView4"
            android:textColor="@android:color/holo_green_light"/>

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/ic_red_cycle"/>

        <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <ImageView
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:background="@drawable/pic_beauty"/>


    </LinearLayout>

至此,OK。运行效果,
在这里插入图片描述

java 方式

通过 LayoutAnimationController 实现。

用前面提到的 R/anim/layout_anim_item.xml 动画文件,

创建动画 animation ,创建 LayoutAnimationController ,ViewGroup.setLayoutAnimation(LayoutAnimationController controller) ,

	public void onLAButtonClick(View view) {
        if (view.getId() == R.id.button_la_hide) {
            mLinearLayout.setVisibility(View.INVISIBLE);

        } else if (view.getId() == R.id.button_la_show) {
            mLinearLayout.setVisibility(View.VISIBLE);

            Animation animation = AnimationUtils.loadAnimation(this, R.anim.layout_anim_item);
            
            LayoutAnimationController controller = new LayoutAnimationController(animation);
            controller.setDelay(0.5f);
            //controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
            controller.setOrder(LayoutAnimationController.ORDER_REVERSE);
            //controller.setOrder(LayoutAnimationController.ORDER_RANDOM);
            
            mLinearLayout.setLayoutAnimation(controller);
        }

    }

很简单,完成,运行效果:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/98746.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

说说你了解的 CDC

分析&回答 什么是 CDC CDC,Change Data Capture,变更数据获取的简称&#xff0c;使用CDC我们可以从数据库中获取已提交的更改并将这些更改发送到下游&#xff0c;供下游使用。这些变更可以包括INSERT,DELETE,UPDATE等。用户可以在以下的场景下使用CDC&#xff1a; 使用f…

ElasticSearch安装为Win11服务

在windows的环境下操作是Elasticsearch,并且喜欢使用命令行 &#xff0c;启动时通过cmd直接在elasticsearch的bin目录下执行elasticsearch ,这样直接启动的话集群名称会默elasticsearch&#xff0c;节点名称会随机生成。 停止就直接在cmd界面按CtrlC 其实我们也可以将elasticse…

说说Flink on yarn的启动流程

分析&回答 核心流程 FlinkYarnSessionCli 启动的过程中首先会检查Yarn上有没有足够的资源去启动所需要的container&#xff0c;如果有&#xff0c;则上传一些flink的jar和配置文件到HDFS&#xff0c;这里主要是启动AM进程和TaskManager进程的相关依赖jar包和配置文件。接着…

6、css学习6(表格)

1、指定CSS表格边框&#xff0c;使用border属性。 2、表格双边框是因为th/td有各自独立的边框。 3、boder-collapse设置表格边框是否被折叠成一个单一的边框。 4、width和height属性定义表格的宽度和高度。 5、text-align属性设置水平对齐方式。 6、vertic-align属性设置垂…

​​​​​​​嵌入式学习笔记(8)ARM汇编伪指令

伪指令的意义 伪指令不是指令&#xff0c;伪指令和指令的根本区别是经过汇编后不会生成机器码。 伪指令的意义在于指导汇编过程。 伪指令是和具体的汇编器有关的&#xff0c;我们使用gnu工具链&#xff0c;因此学习gnu下的汇编伪指令 gnu汇编中的一些符号 用来做注释。 : …

[ES]mac安装es、kibana、ik分词器

一、安装es和kibana 1、创建一个网络&#xff0c;网络内的框架(eskibana)互联 docker network create es-net 2、下载es和kibana docker pull elasticsearch:7.12.1 docker pull kibana:7.12.1 3、运行docker命令部署单点eskibana&#xff08;用来操作es&#xff09; doc…

钡铼技术BL120PN Profinet和Profibus DP转Modbus网关介绍

​ 编辑切换为居中 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; BL120PN是一款Profinet、Profibus D转Modbus网关。 BL120PN下行采集支持&#xff1a;Profinet、Profibus D。 BL120PN上行支持&#xff1a;Modbus RTU、Modbus TCP协议。 BL120PN采…

Message: ‘chromedriver‘ executable may have wrong permissions.

今天运行项目遇到如下代码 driverwebdriver.Chrome(chrome_driver, chrome_optionsoptions)上述代码运行报错如下&#xff1a; Message: chromedriver executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home出错的原…

android开发google账号一键登录和注册

一、官网的使用说明 开始使用一键登录和注册 | Authentication | Google for Developers 二、先到API控制台注册应用添加web应用凭证&#xff0c;注意一定是web应用凭证&#xff0c;如果用android凭证使用时会报错“10: Developer console is not set up correctly”不知…

ROLL.DBF回滚表空间增长问题(达梦数据库)

达梦数据库 - 回滚表空间增长问题 环境介绍1 环境搭建1.1 创建表与测试数据1.2 查询待提交的数据量1.3 查询回滚表空间使用情况1.3.1 插入数据前查询结果1.3.2 插入数据后未提交事务查询结果1.3.3 插入数据后提交事务查询结果 环境介绍 达梦数据库ROLL.DBF 在某些业务系统厂商…

代价高昂的 IT 错误:识别并避免供应商锁定

陷入不提供所需服务的云服务器合同中可能会非常痛苦、令人沮丧且成本高昂。 供应商锁定是提供商难以切换的地方&#xff0c;这意味着企业迁移到新供应商的成本太高、破坏性太大或耗时。 这使得公司受到供应商的摆布&#xff0c;尽管该服务可能无法提供他们所需的可靠性或可扩…

C++之访问vector<vector<char>>中的vector<char>元素(一百八十七)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 人生格言&#xff1a; 人生…

美团北极星榜单,服务零售的医美新样本

事实证明&#xff0c;任何时候&#xff0c;人们对美的追求都是刚需&#xff0c;只是有时候被压抑了。 德勤中国的《中国医美行业2023年度洞悉报告》&#xff08;以下简称“报告”&#xff09;显示&#xff0c;中国医美市场规模预计在2023年超过2000亿元&#xff0c;实现20%增速…

layui--记录

layui 行点击事件&#xff1a;点了没反应&#xff1f; //监听行工具事件layui.table.on(tool(demo), function (obj) {//alert(222) });原因&#xff1a;检查下id与lay-filter是否一致&#xff1b;id与lay-filter必须一致。 <table id"demo" lay-filter"dem…

自助式数据分析平台:JVS智能BI功能介绍(一)数据源

一、数据源配置 数据源概述 数据源是JVS-智能BI支持多种数据形态的基础&#xff0c;核心的目标是将不同的数据来源通过统一接入&#xff0c;实现将不同的数据实现统一的数据加工、数据应用。目前JVS-智能BI主要支持3种形态的数据&#xff1a;数据库、API、离线文件。 ​界面介…

WebGL Varing变量的作用和内插过程,及执行Varing时涉及的图形装配、光栅化、颜色插值、片元着色器执行机制等详解

目录 前言 在 WebGL 或 OpenGL 中&#xff0c;“varying” 是一种用于在顶点着色器和片元着色器之间传递数据的特殊类型的变量。它允许在顶点着色器对数据进行处理后&#xff0c;在片元着色器中使用该处理后的数据进行进一步计算。 彩色三个点 ​编辑 彩色三个点示例代码…

在GPU服务器(Linux)上安装Anaconda和PyTorch环境

安装Anaconda3 Anaconda官网&#xff1a;https://repo.anaconda.com/archive/ 根据自己需要&#xff0c;复制安装包名字&#xff0c;以Anaconda3-2023.07-2-Linux-x86_64.sh为例 命名规则&#xff1a;Anaconda3-<版本号>-Linux-x86_64.sh 在终端输入命令&#xff0c;下…

Flink SQL你用了吗?

分析&回答 Flink 1.1.0&#xff1a;第一次引入 SQL 模块&#xff0c;并且提供 TableAPI&#xff0c;当然&#xff0c;这时候的功能还非常有限。Flink 1.3.0&#xff1a;在 Streaming SQL 上支持了 Retractions&#xff0c;显著提高了 Streaming SQL 的易用性&#xff0c;使…

基于相空间重构的混沌背景下微弱信号检测算法matlab仿真,对比SVM,PSO-SVM以及GA-PSO-SVM

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1 SVM 4.2 PSO-SVM 4.3 GA-PSO-SVM 5.算法完整程序工程 1.算法运行效果图预览 SVM: PSO-SVM: GA-PSO-SVM: 以上仿真图参考文献《基于相空间重构的混沌背景下微弱信号检测方法研究》 2.…

如何成为一名技术社区KOL?

点击文末“阅读原文”即可参与节目互动 剪辑、音频 / 卷圈 运营 / SandLiu 卷圈 监制 / 姝琦 产品统筹 / bobo 联合制作 / RTE开发者社区 录音间 / 声湃轩北京站 在本期节目中&#xff0c;我们请到「开源社」联合创始人&#xff0c;开发者关系领域的畅销书作者林旅强&…