View 动画使用详解

来源:互联网 发布:debian centos 读音 编辑:程序博客网 时间:2024/03/29 15:56

  • View 动画xml编写规范
    • 通用属性
    • translate 平移动画属性详解
    • scale 缩放动画属性详解
    • rotate 旋转动画属性详解
    • alpha 透明度动画属性详解
    • animation的使用

View 动画xml编写规范

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="1000"    android:fillAfter="true"    android:zAdjustment="normal"    android:shareInterpolator="true">    <alpha        android:fromAlpha="float"        android:toAlpha="float" />    <scale        android:fromXScale="float"        android:fromYScale="float"        android:pivotX="float"        android:pivotY="float"        android:toXScale="float"        android:toYScale="float" />    <translate        android:fromXDelta="float"        android:fromYDelta="float"        android:toXDelta="float"        android:toYDelta="float" />    <rotate        android:fromDegrees="float"        android:pivotX="float"        android:pivotY="float"        android:toDegrees="float" /></set>
标签 名称 效果 子类 < translate> 平移动画 移动View TranslateAnimation < scale> 缩放动画 放大或缩小View ScaleAnimation < rotate> 旋转动画 旋转View RotateAnimation < alpha> 透明度动画 改编View的透明度 AlphaAnimation

通用属性

  • android:duration=”1000” 动画持续的时间

  • android:fillAfter=”true” 动画结束后View是否停留在结束位置,true表示停留在结束位置

translate 平移动画属性详解

  • android:fromXDelta=”float” 表示x的起始值, 比如“0”

  • android:fromYDelta=”float” 表示x的结束值,比如“100”

  • android:toXDelta=”float” 表示y的起始值

  • android:toYDelta=”float” 表示y的结束值

scale 缩放动画属性详解

  • android:fromXScale=”float” 水平方向缩放的起始值,如“0.5”

  • android:fromYScale=”float” 垂直方向缩放的起始值,

  • android:pivotX=”float” 缩放轴点x的坐标,默认轴点是中心点,若设置为右边界,那么View只会向左边进行缩放

  • android:pivotY=”float” 缩放轴点y的坐标

  • android:toXScale=”float”水平方向缩放的结束值,如“1.2”

  • android:toYScale=”float” 垂直方向缩放的结束值,

rotate 旋转动画属性详解

  • android:fromDegrees=”float” 旋转开始的角度 比如“0”

  • android:pivotX=”float” 旋转轴点的x坐标,默认为View中心点.

  • android:pivotY=”float” 旋转轴点的y坐标

  • android:toDegrees=”float” 旋转结束的角度 , 比如“180”

alpha 透明度动画属性详解

  • android:fromAlpha=”float” 透明度的起始值 ,比如“0.1”

  • android:toAlpha=”float” 透明度的结束值,比如“1”

animation的使用

Button bt1= ( Button ) findViewById(R.id.bt1);Animation animation= AnimationUtils.loadAnimation(context , R.anim.test_anim);bt1.startAnimation(animation);

可以通过setAnimationListener() 方法给动画添加监听。

 public static interface AnimationListener {        void onAnimationStart(Animation animation);        void onAnimationEnd(Animation animation);        void onAnimationRepeat(Animation animation);    }               
0 0
原创粉丝点击