android开发中常见的几种动画
2016-07-05 10:21
375 查看
动画类型: Tween动画、frame动画、LayoutAnimation动画、PropertyAnimation属性动画。
——————————————————————————————————————————>
Tween Animation动画分类四种:Alpha、Scale、Rotate、translate
动画持续时间,以毫秒为单位、fillAfter() 是否保持动画后的效果
interpolator(动画插入器,加速动画还是减速动画)
repeatCount()动画重复次数
repateMode() 顺序重复还是倒序重复
startOffset() 动画之间的时间间隔(两个动画之间的间隔)
Tween Animation实现方式有两种:
在配置文件中编写
使用java代码实现AlphaAnimation、ScaleAnimation、RotateAnimation、TranslateAnimation;
——————————————————————————————————————————>
控件.startAnimation(传入一个动画对象);
translateAnimation.setAnimationListener( ) 对某个动画对象设置监听
android:startOffset="2000" 多久之后再执行动画?
案例:动画监听器、activity之间的页面跳转动画
布局动画 使用LayoutAnimation类来实现。为View Group添加动画 使用LayoutAnimationController
案例:listView条目散列动画
散列动画案例效果:
——————————————————————————————————————————>
Tween Animation动画分类四种:Alpha、Scale、Rotate、translate
动画持续时间,以毫秒为单位、fillAfter() 是否保持动画后的效果
interpolator(动画插入器,加速动画还是减速动画)
repeatCount()动画重复次数
repateMode() 顺序重复还是倒序重复
startOffset() 动画之间的时间间隔(两个动画之间的间隔)
Tween Animation实现方式有两种:
在配置文件中编写
使用java代码实现AlphaAnimation、ScaleAnimation、RotateAnimation、TranslateAnimation;
——————————————————————————————————————————>
控件.startAnimation(传入一个动画对象);
translateAnimation.setAnimationListener( ) 对某个动画对象设置监听
android:startOffset="2000" 多久之后再执行动画?
案例:动画监听器、activity之间的页面跳转动画
布局动画 使用LayoutAnimation类来实现。为View Group添加动画 使用LayoutAnimationController
案例:listView条目散列动画
package com.example.tuhuadmin.truekeystore; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.animation.AccelerateInterpolator; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ImageView; /** * Created by on 2016/7/4. * PackageName:com.example.tuhuadmin.truekeystore * Author:crs */ public class AnimationActivity extends Activity implements View.OnClickListener { private Button bt1; private Button bt2; private Button bt3; private Button bt4; private Button bt5; private Button bt6; private Button bt7; private Button bt8; private Button btn9; private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animation); initViews(); initListener(); //四种基本动画的实现 //如何实现动画序播? 一个播放完另一个开始播放? 通过为动画设置监听实现 //使用动画集合实现组合动画 //activity之间的页面跳转动画 //布局动画案例 } private void initViews() { bt1 = (Button) findViewById(R.id.bt1); bt2 = (Button) findViewById(R.id.bt2); bt3 = (Button) findViewById(R.id.bt3); bt4 = (Button) findViewById(R.id.bt4); bt5 = (Button) findViewById(R.id.btn5); bt6 = (Button) findViewById(R.id.btn6); bt7 = (Button) findViewById(R.id.btn7); bt8 = (Button) findViewById(R.id.btn8); btn9 = (Button) findViewById(R.id.btn9); iv = (ImageView) findViewById(R.id.iv); } private void initListener() { bt1.setOnClickListener(this); bt2.setOnClickListener(this); bt3.setOnClickListener(this); bt4.setOnClickListener(this); bt5.setOnClickListener(this); bt6.setOnClickListener(this); bt7.setOnClickListener(this); bt8.setOnClickListener(this); btn9.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.bt3: { //透明度动画 fromAlpha 动画起始时的透明度;toAlpha动画结束时的透明度 0.0完全透明 Animation alphaAnimation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.alpha); iv.startAnimation(alphaAnimation); } break; case R.id.bt1: { //哪些参数是规定缩放中心的 使用了android中的插入器 android:pivotX="50%" android:pivotY="50%"; Animation animation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.scale); iv.startAnimation(animation); } break; case R.id.bt4: { //依他本身为原点进行位移 Animation animation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.trtanslate); iv.startAnimation(animation); } break; case R.id.bt2: { //旋转的中心点,旋转的角度从0到360度 //通过代码设置插入器 Animation animation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.rotate); animation.setInterpolator(new AccelerateInterpolator(2f)); iv.startAnimation(animation); } break; case R.id.btn5: { //其实是对动画的监听,如何对动画(动画对象)设置监听? Animation translateAnimation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.trtanslate); final Animation rotateAnimation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.rotate); translateAnimation.setFillAfter(true); iv.startAnimation(translateAnimation); translateAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //动画结束 iv.startAnimation(rotateAnimation); } @Override public void onAnimationRepeat(Animation animation) { } }); } break; case R.id.btn6: { //为后面的哪一个动画设置startOffset属性即可。 Animation animation = AnimationUtils.loadAnimation(AnimationActivity.this, R.anim.continue_set); iv.startAnimation(animation); } break; case R.id.btn7: { //利用动画的setRepeatCount() setRepeatMode() 两个方法实现循环闪烁效果;使用代码的方式实现 AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); alphaAnimation.setRepeatCount(5); alphaAnimation.setDuration(100); alphaAnimation.setRepeatMode(Animation.REVERSE);//倒叙 //alphaAnimation.setRepeatMode(Animation.RESTART);//倒叙 iv.startAnimation(alphaAnimation); } break; case R.id.btn8: { //两个参数,第一个参数是后面activity进入时的动画,第二个是前面的activity退出时的动画 Intent intent = new Intent(AnimationActivity.this, MainActivity.class); startActivity(intent); overridePendingTransition(R.anim.alpha, R.anim.alphacopy); } break; case R.id.btn9: { //布局动画 实现ListView条目 散列效果 Intent intent = new Intent(AnimationActivity.this, ListActivity.class); startActivity(intent); } break; } } }
散列动画案例效果:
package com.example.tuhuadmin.truekeystore; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.AnimationUtils; import android.view.animation.LayoutAnimationController; import android.widget.ArrayAdapter; import android.widget.ListView; import java.util.ArrayList; import java.util.List; /** * Created by on 2016/7/5. * PackageName:com.example.tuhuadmin.truekeystore * Author:crs */ public class ListActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); initViews(); } private void initViews() { ListView lv = (ListView) findViewById(R.id.lv); //准备数据 List<String> list = new ArrayList<>(); for (int i = 0; i < 20; i++) { list.add("chenrushui" + i); } //创建并设置适配器 ArrayAdapter myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, list); lv.setAdapter(myAdapter); //创建布局动画 参数需要一个动画对象 LayoutAnimationController layoutAnimationController = new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.layout_animation)); //条目显示的顺序是可以定制的 layoutAnimationController.setOrder(LayoutAnimationController.ORDER_RANDOM); //为ListView设置布局动画,并启动 lv.setLayoutAnimation(layoutAnimationController); lv.startLayoutAnimation(); } }
相关文章推荐
- Gifski:一个跨平台的高质量 GIF 编码器
- 模仿动画的放大缩小容器
- jQuery 1.9.1源码分析系列(十五)动画处理之缓动动画核心Tween
- Android实现定制返回按钮动画效果的方法
- Android中ViewFlipper的使用及设置动画效果实例详解
- jQuery实现美观的多级动画效果菜单代码
- php判断GIF图片是否为动画的方法
- jQuery实现动画效果circle实例
- HTML5游戏引擎LTweenLite实现的超帅动画效果(附demo源码下载)
- 浅析JavaScript动画
- js排序动画模拟-插入排序
- javascript+HTML5的Canvas实现Lab单车动画效果
- 基于javascript实现漂亮的页面过渡动画效果附源码下载
- js实现按钮颜色渐变动画效果
- 超赞的jQuery图片滑块动画特效代码汇总
- jQuery实现连续动画效果实例分析
- 利用jquery制作滚动到指定位置触发动画
- jQuery实现的给图片点赞+1动画效果(附在线演示及demo源码下载)
- jQuery实现带有洗牌效果的动画分页实例
- jQuery动画效果相关方法实例分析