Anim学习总结
来源:互联网 发布:领主mk vii数据 编辑:程序博客网 时间:2024/06/06 04:12
一、ListView淡入动画效果的实现
(1)、首先,定义每个item的动画效果,在res目录下,创建anim目录,创建以下文件list_anim.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:shareInterpolator="true" > <alpha android:duration="1000" android:fromAlpha="0.0" android:toAlpha="1.0" /></set>
(2)、为lv创建动画文件list_anim_layout.xml
<?xml version="1.0" encoding="utf-8"?><layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:delay="2" android:animationOrder="normal" android:animation="@anim/list_anim"/>
(3)、在布局文件中,为lv添加动画
<!-- android:layoutAnimation="@anim/list_anim_layout" 这句话是添加列表控件的动画,也可以在代码中实现 --> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false" android:scrollbars="vertical" android:layoutAnimation="@anim/list_anim_layout"/>
(4)、在代码中,为lv添加动画效果
推荐在代码中添加,因为在布局中设置,来回刷新,导致只能在第一次进入时,有动画效果
以下代码,放在adapter刷新之前就行:
// 在代码中实现列表动画 Animation animation = (Animation) AnimationUtils.loadAnimation( mContext, R.anim.list_anim); LayoutAnimationController lac = new LayoutAnimationController(animation); lac.setDelay(0.4f); //设置动画间隔时间 lac.setOrder(LayoutAnimationController.ORDER_NORMAL); //设置列表的显示顺序 lv.setLayoutAnimation(lac); //为lv添加动画
二、Drawable动画详解
例如:
<animation-list android:oneshot="true" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:duration="266" android:drawable="@drawable/init_bg_00" /> <item android:duration="66" android:drawable="@drawable/init_bg_01" /> ... <item android:duration="66" android:drawable="@drawable/init_bg_26" /></animation-list>
ImageView iv_anim.setImageResource(R.drawable.init_bg_anim);AnimationDrawable animationDrawable = (AnimationDrawable) iv_anim.getDrawable();animationDrawable.start();
handler.postDelayed(new Runnable() { public void run() { iv_anim.setImageResource(R.drawable.init_bg_anim); AnimationDrawable ad= (AnimationDrawable) iv_anim.getDrawable(); ad.start(); setTimerTask01(); }}, 1000);
三、动画加载的步骤
Animation loadAnimation=AnimationUtils.loadAnimation (getApplicationContext(), R.anim.anim);image.setAnimation(loadAnimation); //为控件设置动画loadAnimation.setFillAfter(true); //停留在结束位置loadAnimation.setFillEnabled(true);loadAnimation.startNow(); //开始动画loadAnimation.cancel(); //取消动画执行
AnimationDrawable animationDrawable = (AnimationDrawable)iv_anim.getDrawable();animationDrawable.stop();iv_anim.setImageResource(R.drawable.init_model);
Animation animation = AnimationUtils.loadAnimation(context,R.anim.init_iamge_big);iv_anim.startAnimation(animation);
四、android:pivotX
五、控制图片缩放的scale动画
//加速
android:interpolator="@android:anim/accelerate_interpolator"
//减速
android:interpolator="@android:anim/decelerate_interpolator"
六、ScaleAnimation
Animation scaleAnimation = new ScaleAnimation(0.1f, 1.0f,0.1f,1.0f);//初始化scaleAnimation.setDuration(500); //设置动画时间this.startAnimation(scaleAnimation);
<scale> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromXScale="1.0" //表示沿着x轴缩放的起始比例 android:toXScale="1.5" //表示沿着x轴缩放的结束比例 android:fromYScale="1.0" //表示沿着y轴缩放的起始比例, android:toYScale="1.5" //表示沿着y轴缩放的结束比例 android:pivotX="50%" //设置动画相对于控件的 x 坐标的位置 android:pivotY="50%" //设置动画相对于控件的 y 坐标的位置 android:duration="2000"/></scale>
七、动画的分类,特点以及区别
八、几种动画类型
ObjectAnimator实现动画
ObjectAnimator.ofFloat(view, "rotationX", 0.0F, 360.0F) .setDuration(500) .start();
ObjectAnimator
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "zhy", 1.0F, 0.0F).setDuration(500);anim.start();anim.addUpdateListener(new AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animation) { float cVal = (Float) animation.getAnimatedValue(); view.setAlpha(cVal); view.setScaleX(cVal); view.setScaleY(cVal); }});
九、overridePendingTransition的简介
使用范例:
Intent intent = new Intent();intent.setClass(SplashActivity.this, MainActivity.class);startActivity(intent);overridePendingTransition(R.anim.splash_screen_fade, R.anim.splash_screen_hold);SplashActivity.this.finish();
R.anim.splash_screen_fade :
<?xml version="1.0" encoding="UTF-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0" />
R.anim.splash_screen_hold :
<?xml version="1.0" encoding="UTF-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_shortAnimTime" android:fromXDelta="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toXDelta="0.0" />
0 0
- Anim学习总结
- Android anim
- android anim
- anim 动画
- Android应用资源总结五:res下的anim和animator文件夹
- android anim 动画效果
- android anim 动画效果
- android-anim实现
- Property Anim详解
- android anim 动画效果
- Property Anim详解
- Android-anim集合
- android anim 动画效果
- Property Anim详解
- android anim 动画效果
- 自定义PopupWindow+BaseAdapter+Anim
- 自定义PopupWindow+SimpleAdapter+Anim
- anim 动画属性详解
- linux 开发环境搭建
- Java回调的原理与实现
- 【 Android Error】 java.lang.NoClassDefFoundError 的解决办法
- 推挽输出和开漏输出区别
- 各版本Xcode下载
- Anim学习总结
- 【个人笔记重点,不作为参考】主题:javascript垃圾收集
- Leetcode 97. Interleaving String
- spring @component的作用
- Async/Await替代Promise的6个理由
- 分组查询
- Hibernate跟JDBC的优缺点
- 第三章 linux内核及内核编程
- Tpcc-MySQL测试