1。Android的动画
1.1。使用动画
Android容许改变对象的属性,在必定的时间间隔经过性能动画API。html
动画的父类的API是动画师 类。objectanimator类能够用来修改对象的属性。android
You can also add ananimatorlistener班你动画师类。 听众称为阶段的在不一样的动画。 可使用此执行操做或后前听众必定的动画,如添加或意见从一个ViewGroup。app
这个(动画)方法一意见对象返回一个viewpropertyanimator为视图对象。 它提供一个API的动画能够执行典型的。ide
下面的代码显示了一个例子。布局
myView.animate().translationX(400); // if an animation is slow you can try to activate a hardware layer which // uses a cache // watch-out: this might not always result in a correct animation myView.animate().translationX(400).withLayer();
你也能够登记行动,这是开始前或结束后执行的动画。性能
// StartAction myView.animate().translationX(100).withStartAction(new Runnable(){ public void run(){ viewer.setTranslationX(100-myView.getWidth()); // do something } }); // EndAction myView.animate().alpha(0).withEndAction(new Runnable(){ public void run(){ // rRemove the view from the parent layout parent.removeView(myView); } });
1.2。定义动画的变化率
经过setinterpolator()你登记的方法timeinterpolator一个动画对象。 率定义的变化为。动画
标准是线性的。 Android平台定义了一些默认的 为例。acceleratedecelerateinterpolator类定义了动画的开始和结束 慢慢加速经过中间。this
1.3。使用动画任意属性
动画系统不能自动理解每种类型 经过。setevaluator方法能够设置类型的对象TypeEvaluator它容许任意。 动画创做类型,评估这些经过提供定制。lua
1.4。布局的动画
这个layouttransition类容许设置动画在布局容器和 的 视图层次 这个集装箱将动画的变化。code
package com.example.android.layoutanimation; import android.animation.LayoutTransition; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class MainActivity extends Activity { private ViewGroup viewGroup; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LayoutTransition l = new LayoutTransition(); l.enableTransitionType(LayoutTransition.CHANGING); viewGroup = (ViewGroup) findViewById(R.id.container); viewGroup.setLayoutTransition(l); } public void onClick(View view) { viewGroup.addView(new Button(this)); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
1.5。活动过渡动画
动画能够应用于意见但它也有可能将这些活动之间的过渡。
这个activityoptions类能够定义默认值或用户的动画。
public void onClick(View view) { Intent intent = new Intent(this, SecondActivity.class); ActivityOptions options = ActivityOptions.makeScaleUpAnimation(view, 0, 0, view.getWidth(), view.getHeight()); startActivity(intent, options.toBundle()); }