Android动画学习Demo(2) 关于Property Animation的用法及总结

Android 动画↑ 1.Android动画 Android系统的动画主要分为三大类: ①View Animation 视图动画:在古老的Android版本系统中就已经提供了,只能被用来设置View的动画。 ②Drawable Animation (也叫Frame动画、帧动画):专门用来一个一个的显示Drawable的resources,就像放幻灯片一样。 ③Property Animation属性动画:只对Android 3.0(API 11)以上版本的Android系统才有效,这种动画可以设置给任何Object,包. 阅读详情

在上一篇文章中,我们知道了关于View Animation的用法及其一些局限性,而在3.0之后,Android 引入了Property Animation 的框架,弥补了View Animation的一些短板,使得我们在Android中能够更好地借助框架去实现更复杂更好的动画效果,从而创造出漂亮的用户体验。

这一篇文章我们先来了解 一下Property Animation的一些用法,在知其然的基础上,下一篇文章我们再来讨论Property Animation的机制原理。

上一篇文章讲到 View Animation 只能作用在View 上,而对那些不是View的对象是不起作用的,而Property Animation则不然,它是对一切对象的一切属性都起作用,只要这个属性有对应的get/set方法。不过话虽然如此说,我个人觉得,动画效果如果我们看不到的话,那有啥意思,而能够让我们看得到的对象,基本上都是View对象,或者间接转化为View对象的。所以,我们还是来关注怎么利用Property Animation来实现View的动画效果吧。

新的属性

首先我们要先了解关于View在3.0之后引入的几个新的属性,并设置了其getter和setter方法:

1)translationX 和 translationY:这两个属性控制了View所处的位置,它们的值是由layout容器设置的,是相对于坐标原点(0,0左上角)的一个偏移量。

2)rotation, rotationX 和 rotationY:控制View绕着轴点(pivotX和pivotY)旋转。

3)scaleX 和 scaleY:控制View基于pivotX和pivotY的缩放。

4)pivotX 和 pivotY:旋转的轴点和缩放的基准点,默认是View的中心点。

5)x 和 y:描述了view在其父容器中的最终位置,是左上角左标和偏移量(translationX,translationY)的和。

6)aplha:透明度,1是完全不透明,0是完全透明。

照例,先上效果Gif,然后再来讲解一下各种效果的实现。


同样的,在Property Animation机制中,同样可以通过XML 或者直接在Java中来定义我们的动画效果。

XML中定义动画效果

比如上面展示中ScaleX 按钮,其效果是在 res/animator/scalex.xml 中定义的,在这里也要说明一下,定义在 animator中不是必须的,但是是android推荐的,因为在eclipse开发中,ADT插件(ADT 11.0.0+)只会去搜寻 res/animator 这个路径,如果不是定义在这个文件夹里面,我们在开发的时候,就没法利用ADT的布局工具了。

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:propertyName="scaleX"
    android:duration="2000"
    android:valueFrom="1.0"
    android:valueTo="2.0"
    android:repeatCount="1"
    android:repeatMode="reverse">
</objectAnimator>
在XML中要利用objectAnimator来定义我们的某个属性的效果,所以:

1)propertyName 当然是一定要的啦,理论上这个属性的值可以是对象中的任何有get/set方法的属性,不过我们这里是对View来说,所以一般而言,就是上面新加的那几种新属性了。

2)duration 持续时间

3)valueFrom 和 valueTo:这就是动画开始和结束时,这个属性相对应的值了,如果我们是缩放的话,当然就是倍数了,如果是平移(Translation)的话,那么就是距离了。

4)repeatCount 和 repeatMode:这两个和View Animation 中是一样的,就不多说了。

在xml中定义好了之后,接下来就要在Java中调用了,如下:

Button btnScaleX = (Button)findViewById(R.id.buttonScaleX);
btnScaleX.setOnClickListener(this);
scaleXAnimator = (ObjectAnimator)AnimatorInflater.loadAnimator(this, R.animator.scalex);
scaleXAnimator.setTarget(btnScaleX);
...
public void onClick(View v) {        
	switch(v.getId()){           	    
	    case R.id.buttonScaleX:
			scaleXAnimator.start();
			break;              
	...    

1)当然,首先要找到我们动画的对象了,在demo中就是那个scaleX的button了。

2)利用AnimationInflater类的loadAnimator方法来获取我们的ObjectAnimator对象

3)利用setTarget(View)方法来设置这个动画应用的对象,在这里就是我们的按钮了。

4)触发动画效果,就是调用其start方法了。

当动画效果开始后,我们发现它就只是在x方向上变大,肿了,那我们要在Y方向上怎么办,在XML中一个ObjectAnimator只能对应于一个属性,所以下面就是Set的展现了,跟View Animation一样,set也是将几个效果给弄在一起,一次性执行也行,顺序执行也行,只要设置其ordering属性就好。

第二个按钮scale,就是在X方向上和Y方向上同时进行的,其定义如下:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:ordering="together">
    <objectAnimator
        android:duration="2000"
        android:propertyName="scaleX"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:valueFrom="1.0"
        android:valueTo="2.0" >
    </objectAnimator>
    <objectAnimator
        android:duration="2000"
        android:propertyName="scaleY"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:valueFrom="1.0"
        android:valueTo="2.0" >
    </objectAnimator>
</set>
而在Java中呢,这个xml对应的对象已经不是ObjectAnimator了,而是AnimatorSet了,其代码如下:

		Button btnScale = (Button)findViewById(R.id.buttonScale);
		btnScale.setOnClickListener(this);
		animatorScaleSet = (AnimatorSet)AnimatorInflater.loadAnimator(this, R.animator.scale);
		animatorScaleSet.setTarget(btnScale);

Java中定义动画效果

我们也可以直接在java中创建OjbectAnimator和AnimatorSet对象,并设置对应的参数和属性,如:

Set

Button buttonSet = (Button) findViewById(R.id.buttonSet);
buttonSet.setOnClickListener(this);
animationSet = new AnimatorSet();
animationSet.playTogether(
		ObjectAnimator.ofFloat(buttonSet, "alpha", 1,0,1),
		ObjectAnimator.ofFloat(buttonSet, "translationX", 0f,400f,0f),
		ObjectAnimator.ofFloat(buttonSet, "rotation", 0,180,360)
		);
animationSet.setDuration(1000);
animationSet.addListener(new AnimatorListener() {			
	@Override
	public void onAnimationStart(Animator arg0) {}
	@Override
	public void onAnimationRepeat(Animator arg0) {}			
	@Override
	public void onAnimationEnd(Animator arg0) {}			
	@Override
	public void onAnimationCancel(Animator arg0) {}			
});
1)我们先通过ObjectAnimator的工厂方法创建几个ObjectAnimator:

1.1)target:动画效果的实施对象,也就是demo中的set按钮。

1.2)propertyName:对应的属性,如alpha,translationX等等。

1.3)values:这是一组值,就是由什么值变动到另外一个什么值,再到什么什么值。。。之类的。

     * @param target The object whose property is to be animated. This object should
     * have a public method on it called <code>setName()</code>, where <code>name</code> is
     * the value of the <code>propertyName</code> parameter.
     * @param propertyName The name of the property being animated.
     * @param values A set of values that the animation will animate between over time.
     * @return An ObjectAnimator object that is set up to animate between the given values.
     */
    public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
        anim.setFloatValues(values);
        return anim;
    }

2)然后通过 AnimatorSet的playTogether方法或者playAfter, playBefore等方法将其加入到set中,如果不加入到set的话,就是对

3)给set设置相对应的如duration之类的属性

4)我们还能够给Animator添加一个Listener,让它能够对Animator的几个关键点进行响应,分别是开始,结束,重复,取消时的响应函数,在这里有一点要注意的就是:

4.1)如果添加的是 AnimatorListener,则其四个函数都要实现

4.2)我们也可以添加 AnimatorListenerAdapter,它是以AnimatorListener的封装,实现了上面的几个空方法,我们只需要实现我们想要的方法就好了,比如:

new AnimatorListenerAdapter() {
	@Override
	public void onAnimationEnd(Animator animator){
		final Button button = (Button) findViewById(R.id.buttonViewPropAnimator);
		button.animate().alpha(1).translationX(0f).start();
	}
})

5)最后在onClick事件中调用其start方法。

不过在Java中,如果要实现一个对象不同属性的动画效果,除了Set,我们还可以利用PropertyValuesHolder和ViewPropertyAnimator对象来实现,具体做法如下:

PropertyValuesHolder

PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("translationX",0f,300f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("translationY",0f,300f);		
translateAnimator = ObjectAnimator.ofPropertyValuesHolder(buttonProValHolder, pvhX,pvhY);
translateAnimator.setDuration(2000);

1)我们可以通过 PropertyValuesHolder类的工厂方法ofInt, ofFloat等方法,让它能够Hold住对应property的value。
2)在利用ObjectAnimator的ofPropertyValuesHolder方法时,再将我们上面定义的propertyValuesHolder给传进去,定义出一个objectAnimator。
3)设置objectAnimator对应的属性,调用其Start方法就行。

ViewPropertyAnimator

也可以通过ViewPropertyAnimator类来实现,如下:
case R.id.buttonViewPropAnimator:
	v.animate().translationX(100f).alpha(0).setListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animator){
			final Button button = (Button) findViewById(R.id.buttonViewPropAnimator);
			button.animate().alpha(1).translationX(0f).start();
		}
	}).start();
1)先利用view的animate() 方法返回一个ViewPropertyAnimator对象,然后调用其translationX,alpha等方法,也可以给其添加listener。
2)最后调用其start方法即可。

关于ValueAnimator

从上面的代码中,我们可以发现,我们好像都是在用ObjectAnimator对象,那么ValueAnimator类呢?其实ObjectAnimator是ValueAnimator的一个子类,是比较常用的一个类。
但是有时候如果ObjectAnimator不能满足我们的需求了,那么我们就要用ValueAnimator类了。但是我们留到下一篇文章讲Property Animation的工作原理的时候再讲吧。
(Tips. 其实demo中已经有一个ValueAnimator的实现了,各位可以先看一下)。

源代码请点击(请记住,上述属性是3.0后才支持的!!!)


P.S. 大家有没有发现,在View Animation中,当我们移动一个按钮到另外一个地方的时候,要响应按钮的点击事件的时候,我们必须在原来的位置点击,那么在Property Animation中呢,当然是不用啦,大家可以在demo中试试。

P.S. 大家有没有发现,PropertyAnimation基本上都是用animator,而不是用animation了呢?

P.S. 大家如果有兴趣,还可以了解一下View Animation 是怎么样的呢,传送门:

Android动画学习Demo(1) 关于ViewAnimation的用法及总结

定时移动鼠标点击鼠标,防止电脑息屏的vba脚本 定时移动鼠标,使系统始终处于激活状态,防止系统息屏。 阅读详情

相关推荐

基于Agent与大模型的性能测试脚本自动化生成实践

性能测试是软件质量保障的关键环节,其核心在于模拟真实用户负载以评估系统在高并发下的表现。传统脚本编写依赖人工,效率低下且易出错。通过引入智能体(Agent)与大语言模型(LLM)技术,可实现从自然语言描述或接口文档到可执行脚本的自动化转换。Agent负责任务规划与工具调用,LLM则提供强大的意图理解与代码生成能力,二者结合能精准解析测试场景、自动处理参数化与接口关联等复杂逻辑。该技术方案显著提升了脚本生成效率与准确性,尤其适用于持续集成、海量接口回归等需要快速构建测试场景的工程实践。本文以JMeter和Lo

weixin_28718769的博客 259

帧动画

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_pa

xdd_lmd的博客 756

细胞膜电学特性的分数阶微积分建模

分数阶微积分在细胞膜电学特性建模中的应用主要体现在对细胞膜的电容行为和神经元放电活动的更精确描述上。

冰河世纪20的博客 623

做动画步骤,对于使用adt-bundle-windows-x86-20131030的用户

当初搭建Android开发平台,由于用自带ADT下载

u010102493的专栏 2003

RT-Thread新手必看:FMT飞控移植中的5个常见坑及解决方案

本文针对RT-Thread新手在移植FMT开源飞控时遇到的5大核心挑战,提供了深度解决方案。内容涵盖SCons构建系统配置、RT-Thread版本API兼容性处理、BSP与设备驱动适配、TOML系统配置解析以及算法模块集成调试,帮助开发者高效避坑,成功完成飞控移植。

gin88的博客 251

win10自动修复-无限循环【通用完美】超简单解决办法

2020.02.14今个我的笔记本电脑(Thinkpad Carbon 7 X1)(win10)早晨起来发现蓝屏,上面显示自动修复失败,重启后依然自动修复失败,不断手动重启,始终是修复失败。然后上网开始搜集资料找解决办法。 前边介绍关闭自动修复,如何找出错文件的方法;如果想看最终解决办法,直接看第三部分 上网就会发现这种现象很常见,同时是电脑自动安装系统更新,或者安装某些驱动出现。解决办法也大...

y15941300574的博客 19万+

android动画基础

一 传统 View 动画(Tween/Frame) 转自:http://www.codekk.com/open-source-project-analysis/detail/Android/lightSky/%E5%85%AC%E5%85%B1%E6%8A%80%E6%9C%AF%E7%82%B9%E4%B9%8B%20Android%20%E5%8A%A8%E7%94%BB%E5%9F%BA%

u014134488的专栏 568

北斗三号PPP-B2b信号实战指南:从接收机配置到精度验证全流程

本文提供了北斗三号PPP-B2b信号从硬件配置到数据处理的全流程实战指南。详细解析了信号特性、接收机关键参数设置,并以飞纳接收机和Mass软件为例,演示了数据解算与精度验证方法。通过覆盖中国多地区的联调测试案例,验证了PPP-B2b服务可实现分米级实时定位精度,为无网络地区高精度应用提供了可靠解决方案。

nn3456的博客 554

Android动画之视图动画和属性动画

Android 动画分为两大类,分别是视图动画(View Animation)和属性动画(Property Animation)。对于这两种动画,都能够使用xml和代码的形式定义动画。View Animation视图动画是Android最基础的动画,在API 1中就已经加入,不需考虑兼容性,但由于其动画只是作用于视图上,而不会由该控件的属性,所以有很多的局限性。视图动画的基类是Animation其下

茅屋 1万+

【异常】OpenClaw LLM请求超时异常LLM request timed out.的技术分析与解决方案

LLM请求超时是OpenClaw工程化落地中最常见的链路稳定性问题,排查处置需遵循标准化的分级流程。绝大多数场景可通过重试、调整超时配置、优化模型选型快速解决;针对顽固型异常,可通过全链路日志拆解超时阶段,精准定位根因并完成针对性修复,最终保障OpenClaw业务链路的稳定运行。

奶爸的编程之路,也就一周冷个三天 1990

MOS管的体二极管在LLC中的作用

MOSFET是一个三端器件(G、D、S),在N沟道MOSFET的结构中,源极和漏极之间的N型材料中自然形成了一个寄生的PN结,这个PN结就是体二极管(Body Diode),它是不可避免的器件结构。📌 对于N沟MOSFET:体二极管是从漏极 D 到源极 S 的正向导通二极管,方向为 D → S。MOS管的体二极管在LLC中并不是主功率通道,但却是实现软开关(ZVS)和能量过渡的关键“临时路径”。用得好,它是你的朋友;忽略它,电路就可能烧毁。

weixin_43199439的博客 700

Android动画学习Demo(1) 关于ViewAnimation的用法及总结

在Android系统中,提供了两种动画框架: 1)View Animation(视图动画),而View Animation 里面又包含了下面两种模式 1.1)Tween Animation (也称之为View Animation) 1.2)Frame Animation (也称之为Drawable Animation) 2)Property Animation(属性动画),这是在Android 3.0(API Level 11)之后才支持的框架。 所以,不考虑层次,只考虑实现,Android中就存在以下

持剑 6489

机器视觉工程师如何进行高速运动物体捕获

硬件方面使用高帧率相机(如工业相机、高速摄像机)确保充足的光照条件使用高性能计算平台减少处理延迟软件方面背景减除技术快速分离运动物体卡尔曼滤波预测物体轨迹ROI技术减少计算量多线程处理提高实时性实际应用中的关键考量针对特定场景调整参数(如阈值、滤波器参数等)平衡计算资源与实时性要求结合特定领域知识优化算法(如物体运动特性)上述示例代码实现了一个基础的高速物体跟踪系统,通过背景减除和卡尔曼滤波实现对高速物体的检测和跟踪。

zhangzhechun_02的博客 625

Android动画学习Demo(3) 关于Property Animation的TimeInpolator和TypeEvaluator

Property Animation中最重要,最基础的一个类就是ValueAnimator了。Property Animation利用ValueAnimator来跟踪记录对象属性已经变化了多长时间及当前这个时间点的值。 ... 总的来说,就是三步: 1)将时间的消逝 t 和时长 duration 的比例fraction,传给interpolator 算出一个新的fractionNew。 2)将这个fractionNew传给TypeEvaluator,算出对应属性的当前值animatedValue。 3)根据

持剑 9176

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Android动画了解—属性动画(Property Animation)

在Android中,动画分为两类:视图动画

Android TV 开发 1572

深度学习工具包 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")

Android动画

Android动画主要分为帧动画(逐帧播放图片序列)、补间动画(仅改变视觉位置)和属性动画(实际修改对象属性)。属性动画通过改变视图真实属性值实现交互同步,而补间动画只影响绘制效果。修改Activity转场动画可通过主题定义或代码调用overridePendingTransition实现,支持平移/缩放等效果。属性动画Demo展示了按钮移动后仍能响应点击的原理:ObjectAnimator直接操作translationX属性,触发视图和触摸区域同步更新。相比补间动画的视觉假象,属性动画实现了真正的物理位移和

xingfuyisheng的专栏 983

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Android动画之属性动画(Property Animation)(一)

由于Android3.0之前已经有的视图动画(View Animation)存在一些局限性------动画改编的只是显示,并不能响应事件。View Animation相当简单,不过只能支持简单的缩放、平移、旋转、透明度基本的动画,且有一定的局限性。View Animation的动画框架所产生的动画,并不能改变事件响应的位置,它只是单纯地修改了显示。如果使用旧的视图动画产生上面的效果,那么按钮的实际点击有效区依然。。。

Picasso_L的专栏 1662

Android 属性动画(Property Animation) ValueAnimator 的介绍

先说下属性动画与视图动画的区别: 视图动画系统仅提供为 View对象添加动画效果的功能,因此,如果您想为非 对象添加动画效果,则必须实现自己的代码才能做到。视图动画系统也存在一些限制,因为它仅公开 对象的部分方面来供您添加动画效果;例如,您可以对视图的缩放和旋转添加动画效果,但无法对背景颜色这样做。 视图动画系统的另一个缺点是它只会在绘制视图的位置进行修改,而不会修改实际的视图本身。例如,如果您为某个按钮添加了动画效果,使其可以在屏幕上移动,该按钮会正确绘制,但能够点击按钮的实际位置并不会更改,因此您.

小牧在一直在学习,在前进的道路上大家一起学习,进步。 690

Android动画之属性动画(Property Animation)(三)

所谓布局动画是指作用在ViewGroup上,给ViewGroup增加view时添加一个动画过渡效果。

Picasso_L的专栏 792

Android 属性动画(Property Animation) ObjectAnimator的介绍

先说下属性动画与视图动画的区别: 视图动画系统仅提供为 View对象添加动画效果的功能,因此,如果您想为非 对象添加动画效果,则必须实现自己的代码才能做到。视图动画系统也存在一些限制,因为它仅公开 对象的部分方面来供您添加动画效果;例如,您可以对视图的缩放和旋转添加动画效果,但无法对背景颜色这样做。 视图动画系统的另一个缺点是它只会在绘制视图的位置进行修改,而不会修改实际的视图本身。例如,如果您为某个按钮添加了动画效果,使其可以在屏幕上移动,该按钮会正确绘制,但能够点击按钮的实际位置并不会更改,因此您.

小牧在一直在学习,在前进的道路上大家一起学习,进步。 1090

Android animation学习笔记之propery animation

以前写博客都是用百度空间,总感觉不专业,访问量少,好友少,里边可运用的资源也少,所以昨天网上查了一下,觉得iteye社区还不错,就申请了一个iteye帐号,今天开始写博,希望大家多关注多交流,共同进步.       最近一直在做中国最强音app的开发,好不容易闲了下来,觉得在做中国最强音app的时候动画方面的知识还不够扎实,所以这周腾出手来主要学习了animation和graphics

让我们一起摇摆 1633

android 属性动画集合,Android动画合集之属性动画Property Animation

1.属性动画概念2.ValueAnimator简单使用ValueAnimator的用法却一点都不复杂,我们先从最简单的功能看起吧,比如说想要将一个值从0平滑过渡到1,时长300毫秒,就可以这样写:ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);anim.setDuration(300);anim.start();怎么样?很简单吧,调用Value...

weixin_40005454的博客 301

android曲线位移动画,Android动画学习Demo(3) 沿着贝塞尔曲线移动的Property Animation...

Property Animation中最重要,最基础的一个类就是ValueAnimator了。Property Animation利用ValueAnimator来跟踪记录对象属性已经变化了多长时间及当前这个时间点的值。android而在ValueAnimator中,又封装了两个类:ide1)TimeInterpolator,也称插值器,是来计算当前动画运动的一个跟时间有关系的比例因子。函数2)Ty...

weixin_36289211的博客 455

android 属性动画入门

android 属性动画入门

zhouguizhi 1852

帅气的属性动画赏析(Property Animation)

权利声明:转载请注明出处http://blog.youkuaiyun.com/hello_chillax今天我们来学习Android中的一个比较好玩的动画效果:Property Animation、でわ、はじめましょう。一,初めに:动画的分类 Android动画分类:View Animation,Drawable Animation,Property Animation。各自能实现的效果:View Anima

企鹅肖 1282
上一篇: Android动画学习Demo(1) 关于ViewAnimation的用法及总结
下一篇: Android动画学习Demo(3) 关于Property Animation的TimeInpolator和TypeEvaluator
linmiansheng
博客等级 码龄20年 507粉丝 111原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值