为Viewgourp内组件添加动画
package com.loaderman.customviewdemo; import android.animation.Keyframe;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout; public class MainActivity extends AppCompatActivity {
private LinearLayout linearLayoutContainer; private int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayoutContainer = (LinearLayout) findViewById(R.id.linearlayoutcontainer); // LayoutTransition transition = new LayoutTransition();
// //入场动画:view在这个容器中消失时触发的动画
// ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "rotationY", 0f, 360f, 0f);
// transition.setAnimator(LayoutTransition.APPEARING, animIn);
//
// //出场动画:view显示时的动画
// ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "rotation", 0f, 90f, 0f);
// transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
//
// PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 0);
// PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 0);
// PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
// Animator changeAppearAnimator
// = ObjectAnimator.ofPropertyValuesHolder(linearLayoutContainer, pvhLeft, pvhTop, pvhScaleX);
// transition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeAppearAnimator); LayoutTransition transition = new LayoutTransition();
PropertyValuesHolder outLeft = PropertyValuesHolder.ofInt("left", 0, 0);
PropertyValuesHolder outTop = PropertyValuesHolder.ofInt("top", 0, 0); Keyframe frame0 = Keyframe.ofFloat(0f, 0);
Keyframe frame1 = Keyframe.ofFloat(0.1f, -20f);
Keyframe frame2 = Keyframe.ofFloat(0.2f, 20f);
Keyframe frame3 = Keyframe.ofFloat(0.3f, -20f);
Keyframe frame4 = Keyframe.ofFloat(0.4f, 20f);
Keyframe frame5 = Keyframe.ofFloat(0.5f, -20f);
Keyframe frame6 = Keyframe.ofFloat(0.6f, 20f);
Keyframe frame7 = Keyframe.ofFloat(0.7f, -20f);
Keyframe frame8 = Keyframe.ofFloat(0.8f, 20f);
Keyframe frame9 = Keyframe.ofFloat(0.9f, -20f);
Keyframe frame10 = Keyframe.ofFloat(1, 0); PropertyValuesHolder mPropertyValuesHolder = PropertyValuesHolder.ofKeyframe("rotation", frame0, frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9, frame10);
ObjectAnimator mObjectAnimatorChangeDisAppearing = ObjectAnimator.ofPropertyValuesHolder(this, outLeft, outTop, mPropertyValuesHolder);
transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, mObjectAnimatorChangeDisAppearing); transition.addTransitionListener(new LayoutTransition.TransitionListener() {
public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
Log.d("loaderman", "start:" + "transitionType:" + transitionType + "count:" + container.getChildCount() + "view:" + view.getClass().getName());
} public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
Log.d("loaderman", "end:" + "transitionType:" + transitionType + "count:" + container.getChildCount() + "view:" + view.getClass().getName());
}
}); linearLayoutContainer.setLayoutTransition(transition);
findViewById(R.id.add_btn).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
addButtonView();
}
}); findViewById(R.id.remove_btn).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
removeButtonView();
}
}); } private void addButtonView() {
i++;
Button button = new Button(this);
button.setText("button" + i);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
button.setLayoutParams(params);
linearLayoutContainer.addView(button, 0);
} private void removeButtonView() {
if (i > 0) {
linearLayoutContainer.removeViewAt(0);
}
i--;
} }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <Button
android:id="@+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="添加控件"/> <Button
android:id="@+id/remove_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="移除控件"/>
</LinearLayout> <LinearLayout
android:id="@+id/linearlayoutcontainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:orientation="vertical"/> </LinearLayout>
效果:

Android提供四种方法为viewgroup组件添加动画
1.LayoutAnimation和LayoutAnimationControllerz主要针对listview
2.gridLayoutAnimation主要针对gridview
3.android:animateLayoutChanges 属性 xml布局设置为true则带有默认动画,动画不能自定义
4.layoutTranstion最为强大,动画可以自定义
void setAnimator(int transitionType,Animator animator) 其中:transition取值如下
- LayoutTransition.APPEARING :元素在容器中出现时所定义的动画
 - LayoutTransition.DISAPPEARING : 元素在容器中消失时所定义的动画
 - LayoutTransition.CHANGE_APPEARING : 由于元素中显示新的元素,其他需要变化的元素所对应的动画
 - LayoutTransition.CHANGE_DISAPPEARING: : 同上,相反,某个元素消失时,所对应的元素动画
 
为Viewgourp内组件添加动画的更多相关文章
- form-create教程:给内置组件和自定义组件添加事件
		
本文将介绍form-create如何给内置组件和自定义组件添加事件 form-create 是一个可以通过 JSON 生成具有动态渲染.数据收集.验证和提交功能的表单生成器.并且支持生成任何 Vue ...
 - [Mugeda HTML5技术教程之7]添加动画
		
前一节我们讲述了怎么在新建的作品中添加元素,元素加好以后我们还想让他们动起来,来实现比较炫的效果.这节我们将要讲述怎么给元素添加动画.Mugeda动画是通过时间轴和帧来实现的.通过在时间轴上创建图层和 ...
 - Html5页面内使用JSON动画的实现
		
有一天我们的UI设计师找到我说,要把页面中我自己用程序写的动画,换成他们给的json动画,原因是有的动画很复杂,自己写起来达不到他们的预期效果(写到这里我突然想到一个问题,这么复杂的动画为什么不使用g ...
 - XamarinAndroid组件教程RecylerView动画组件使用动画(3)
		
XamarinAndroid组件教程RecylerView动画组件使用动画(3) (8)打开Main.axml文件,构建主界面.代码如下: <?xml version="1.0&quo ...
 - XamarinAndroid组件教程RecylerView动画组件使用动画(2)
		
XamarinAndroid组件教程RecylerView动画组件使用动画(2) 如果开发者要为RecylerView的子元素添加动画效果,需要使用RecyclerView类中的SetItemAnim ...
 - React动画组件——React-Transitio-group动画实现
		
React动画组件--React-Transitio-group动画实现 安装 项目目录下使用命令行 yarn add react-transition-group 安装组件.在需要使用动画的页面加入 ...
 - Java 给PPT添加动画效果(预设动画/自定义动画)
		
PPT幻灯片中对形状可设置动画效果,常见的动画效果为内置的固定类型,即动画效果和路径是预先设定好的固定模板,但在设计动画效果时,用户也可以按照自己的喜好自定义动画动作路径.下面,通过Java后端程序代 ...
 - extjs组件添加事件监听的三种方式
		
extjs对组件添加监听的三种方式 在定义组件的配置时设置 如代码中所示: Java代码 xtype : 'textarea', name : 'dataSetField', labelSe ...
 - SWT组件添加事件的四种方式
		
在我们CS日常开发过程中会经常去为组件添加事件,我们常用的为AWT与SWT.SWT的事件模型是和标准的AWT基本一样的.下面将按照事件的四种写法来实现它. 一.匿名内部类的写法 new MouseAd ...
 
随机推荐
- nginx连接php测试
			
1 nginx连接php [root@web01 /application/nginx/conf/conf.d]# cat docs.conf server { server_name docs.ol ...
 - Alpha2版本相互测试
			
[作业信息] Q A 作业所属课程 https://edu.cnblogs.com/campus/xnsy/2019autumnsystemanalysisanddesign/ 作业要求 https: ...
 - Java枚举的小例子
			
有一次工作中,要根据多个参数确定一个值(车辆事件),确定一个值需要的参数大部分的属性名称是相同的,少部分是独有的,但是参数的值几乎都是不同的: 因为参数太多,if-else写起来就太不优雅了,可以参考 ...
 - MyBatis3-topic04,05 -接口式编程
			
笔记要点 /**接口式编程: * 1. 原生: Dao 接口-->Dao接口的实现类 * mybatis: Mapper --> 有一个与之对应的 XXMapper.xml * 2. Sq ...
 - 使用Nginx实现反向代理 - 不同的子域名映射到不同的后台地址
			
1.配置IP域名 C:\Windows\System32\drivers\etc\hosts中加入 127.0.0.1 8081.max.com 127.0.0.1 8082.max.com 2.配置 ...
 - vue 自定义全局组件
 - JSP中9大内置对象类型
			
JSP中九大内置对象为: request 请求对象 类型 javax.servlet.ServletRequest 作用域 Requ ...
 - Lavavel Lifecycle
 - parted分区命令
			
Parted是一个比fdisk更高级的工具,它支持多种分区表格式,包括MS-DOS和GPT.它允许用户创建,删除,调整大小,缩小,移动和复制分区,重新组织磁盘使用,以及将数据复制到新硬盘,但在缩小分区 ...
 - P1143 进制转换
			
漂亮小姐姐点击就送:https://www.luogu.org/problemnew/show/P1143 题目描述 请你编一程序实现两种不同进制之间的数据转换. 输入输出格式 输入格式: 输入数据共 ...