Animation 笔记

来源:互联网 发布:淘宝代刷信誉是真的吗 编辑:程序博客网 时间:2024/06/17 21:58

Animation 笔记


一、TranslateAnimation

(1)、从下方移入到当前位置(移动高度为视图高度)

xml格式

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="0%"    android:toXDelta="0%"    android:fromYDelta="100%"    android:toYDelta="0%"     android:duration="500"    android:fillAfter="true"    android:interpolator="@android:anim/accelerate_interpolator"    />

代码格式

openAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,       Animation.RELATIVE_TO_SELF, 0,Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f);R.anim.from_down_translate);        openAnimation.setDuration(500);        openAnimation.setFillAfter(true);

(2)、从下方移出当前位置(移动高度为视图高度)

xml格式

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXDelta="0%"    android:toXDelta="0%"    android:fromYDelta="0%"    android:toYDelta="100%"     android:duration="500"    android:fillAfter="true"    android:interpolator="@android:anim/decelerate_interpolator"    />

代码格式

closeAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,                Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);        closeAnimation.setDuration(500);        closeAnimation.setFillAfter(true);

二、ScaleAnimation

(1)、以视图中心为中心,由0~1不断伸展开

xml格式

<scale     android:fromXScale="0"    android:toXScale="1"    android:fromYScale="0"    android:toYScale="1"    android:duration="500"    android:pivotX="50%"    android:pivotY="50%"    android:fillAfter="true"/>

代码格式

scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);scaleAnimation.setDuration(500);scaleAnimation.setFillAfter(true);

三、组合效果

(1)、先从0~1不断展开,然后向右上角移动一个视图单位

图片的所在的真实位置是效果结束时的位置

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">  <scale     android:fromXScale="0"    android:toXScale="1"    android:fromYScale="0"    android:toYScale="1"    android:duration="500"    android:pivotX="50%"    android:pivotY="50%"    android:fillAfter="true"/><translate     android:fromXDelta="-100%"    android:toXDelta="0%"    android:fromYDelta="100%"    android:toYDelta="0%"     android:duration="500"    android:startOffset="500"    android:fillAfter="true"/></set>

(2)、先向左下角移动一个视图单位,然后从1~0不断缩小

图片的真实位置是效果开始时的位置

<translate     android:fromXDelta="0%"    android:toXDelta="-100%"    android:fromYDelta="0%"    android:toYDelta="100%"     android:duration="500"    android:fillAfter="true"/><scale     android:fromXScale="1"    android:toXScale="0"    android:fromYScale="1"    android:toYScale="0"    android:pivotX="-50%"    android:pivotY="150%"    android:duration="500"    android:startOffset="500"    android:fillAfter="true"/>

注:虽然这两个组合效果是逆向的,但是缩放效果的中心点的表达方式却不一样。
第一个是以移动前的视图为参考物的。(不是很理解)
第二个是以真实的视图为参考物的。
假设:移动是以真实视图为中心,缩放是以初始视图为中心。

0 0
原创粉丝点击