您的位置:首页 > 运维架构

三种动画效果(Frame, View, Property)实现

2016-07-24 19:01 369 查看
Frame/View/Property,是哪些版本加入的,并向前兼容??组合动画?

纯Java代码或XML与Java实现??

Android动画- http://blog.csdn.net/q4878802/article/category/5671159
Android动画- http://blog.csdn.net/q4878802/article/category/5671159
Android 用Animation-list实现逐帧动画:http://blog.csdn.net/aminfo/article/details/7847761

Android开发—View动画、帧动画和属性动画详解-- http://blog.csdn.net/SEU_Calvin/article/details/52724655
Android动画之一,Drawable Animation: http://blog.csdn.net/chziroy/article/details/40424343
Android动画效果translate、scale、alpha、rotate详解- http://blog.csdn.net/sun6255028/article/details/6735025
Android开发--图形图像与动画(二)--Animation实现图像的 渐变、缩放、位移、旋转- http://blog.csdn.net/dlutbrucezhang/article/details/8543708
package com.desaco.differentanimation.frame_animation;

import com.desaco.differentanimation.R;

import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.Window;

import android.widget.Button;

import android.widget.ImageView;

public class FrameAnimationActivity extends Activity {
private ImageView animationIV;
private Button buttonA, buttonB, buttonC;
private AnimationDrawable animationDrawable;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_frame_animation);

animationIV = (ImageView) findViewById(R.id.animationIV);
buttonA = (Button) findViewById(R.id.buttonA);
buttonB = (Button) findViewById(R.id.buttonB);
buttonC = (Button) findViewById(R.id.buttonC);
// 顺序显示
buttonA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.frame_order_animation);
animationDrawable = (AnimationDrawable) animationIV
.getDrawable();
animationDrawable.start();
}

});
// 停止
buttonB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationDrawable = (AnimationDrawable) animationIV
.getDrawable();
animationDrawable.stop();
}

});
// 倒序显示
buttonC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV
.setImageResource(R.drawable.frame_reverse_animation);
animationDrawable = (AnimationDrawable) animationIV
.getDrawable();
animationDrawable.start();
}
});
}

}
 > frame_order_animation.xml

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot="true" >

    <item

        android:drawable="@drawable/wifi_0"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_1"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_2"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_3"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_4"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_5"

        android:duration="150">

    </item>

</animation-list>

> frame_reverse_animation.xml

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot="true" >

    <item

        android:drawable="@drawable/wifi_5"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_4"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_3"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_2"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_1"

        android:duration="150">

    </item>

    <item

        android:drawable="@drawable/wifi_0"

        android:duration="150">

    </item>

</animation-list>

> Android View动画(补间动画):http://blog.csdn.net/sgx425021234/article/details/9195829   http://blog.csdn.net/CHZiroy/article/details/40456399

AlphaAnimation:透明度(alpha)渐变效果,对应<alpha/>标签。

TranslateAnimation:位移渐变,需要指定移动点的开始和结束坐标,对应<translate/>标签。

ScaleAnimation:缩放渐变,可以指定缩放的参考点,对应<scale/>标签。

RotateAnimation:旋转渐变,可以指定旋转的参考点,对应<rotate/>标签。

AnimationSet:组合渐变,支持组合多种渐变效果,对应<set/>标签。

> Android图文详解属性动画: http://www.mamicode.com/info-detail-1150209.html   http://blog.csdn.net/lmj623565791/article/details/38067475

> 动画

import android.view.animation.Animation

Animation ivAnimation = AnimationUtils.loadAnimation(this,

                R.anim.dash_scale);

Animation ivAnimation = AnimationUtils.loadAnimation(this,

                R.anim.dash_scale);

        ImageView imageView = (ImageView) favourView

                .findViewById(R.id.iv_favour);

        imageView.setImageResource(R.drawable.xf_comment_like_c);

        imageView.startAnimation(ivAnimation);

<?xml version="1.0" encoding="utf-8"?>

<set

  xmlns:android="http://schemas.android.com/apk/res/android">

    <alpha android:duration="200" android:pivotX="50.0%" android:pivotY="75.0%" android:fromAlpha="0.0" android:toAlpha="1.0" />

    <scale android:duration="200" android:pivotX="50.0%" android:pivotY="75.0%" android:fromXScale="0.38" android:toXScale="1.1" android:fromYScale="0.38" android:toYScale="1.1" />

    <scale android:duration="240" android:pivotX="50.0%" android:pivotY="75.0%" android:startOffset="200" android:fromXScale="1.1" android:toXScale="0.85" android:fromYScale="1.1" android:toYScale="0.85" />

    <scale android:duration="160" android:pivotX="50.0%" android:pivotY="75.0%" android:startOffset="440" android:fromXScale="0.95" android:toXScale="1.07" android:fromYScale="0.95" android:toYScale="1.07" />

</set>

------------------------------------------

/*

     * 加载中

     */

    protected void MyPostExecuteProgress() {

        AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);

        animation.setDuration(400);

        in_xf_huxing_progress.startAnimation(animation);

        animation.setAnimationListener(new Animation.AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                // 动画结束时执行此方法

                progress.setVisibility(View.GONE);

            }

        });

    }

----------------------------------------------------------------

> 属性动画,SDK3.0加入的

// 1.属性动画-旋转Rotate

// 动画实际执行  

    private void startPropertyAnim() {  

        // 第二个参数"rotation"表明要执行旋转  

        // 0f -> 360f,从旋转360度,也可以是负值,负值即为逆时针旋转,正值是顺时针旋转。  

        ObjectAnimator anim = ObjectAnimator.ofFloat(text, "rotation", 0f, 360f);  

        // 动画的持续时间,执行多久?  

        anim.setDuration(5000);   

        // 回调监听  

        anim.addUpdateListener(new AnimatorUpdateListener() {  

  

            @Override  

            public void onAnimationUpdate(ValueAnimator animation) {  

                float value = (Float) animation.getAnimatedValue();  

                Log.d("zhangphil", value + "");  

            }  

        });  

  

        // 正式开始启动执行动画  

        anim.start();  

    } 

// 2.透明度渐变属性动画,此处将实现属性动画的动画实际执行  

    private void startPropertyAnim() {  

        // 将直接把TextView这个view对象的透明度渐变。  

        // 注意第二个参数:"alpha",指明了是透明度渐变属性动画  

        // 透明度变化从1—>0.1—>1—>0.5—>1,TextView对象经历4次透明度渐变  

        ObjectAnimator anim = ObjectAnimator.ofFloat(text, "alpha", 1f, 0.1f, 1f, 0.5f, 1f);  

  

        anim.setDuration(5000);// 动画持续时间  

  

        // 这里是一个回调监听,获取属性动画在执行期间的具体值  

        anim.addUpdateListener(new AnimatorUpdateListener() {  

  

            @Override  

            public void onAnimationUpdate(ValueAnimator animation) {  

                float value = (Float) animation.getAnimatedValue();  

                Log.d("zhangphil", value + "");  

            }  

        });  

  

        anim.start();  

    }  

// 3.位移动画,translationX,translationY

    private void startPropertyAnim() {  

        // X轴方向上的坐标  

        float translationX = text.getTranslationX();  

  

        // 向右移动500pix,然后再移动到原来的位置复原。  

        // 参数“translationX”指明在x坐标轴位移,即水平位移。  

        ObjectAnimator anim = ObjectAnimator.ofFloat(text, "translationX", translationX, -500f, translationX);  

  

        anim.setDuration(5000);  

  

        // 回调监听,可以有也可以无。  

        // 根据情况,如果需要监听动画执行到何种“进度”,那么就监听之。  

        anim.addUpdateListener(new AnimatorUpdateListener() {  

  

            @Override  

            public void onAnimationUpdate(ValueAnimator animation) {  

                float value = (Float) animation.getAnimatedValue();  

                Log.d("zhangphil", value + "");  

            }  

        });  

  

        // 正式开始启动执行动画  

        anim.start();  

    } 

// 4.scale缩放动画 ,scaleX,scaleY,

 public void propertyValuesHolder(View view) {

        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);

        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 1f);

        PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 1f);

        ObjectAnimator.ofPropertyValuesHolder(view, pvhX, pvhY, pvhZ).setDuration(1000).start();

    }

// 动画实际执行  

    private void startPropertyAnim() {  

        // 将一个TextView沿垂直方向先从原大小(1f)放大到5倍大小(5f),然后再变回原大小。  

        ObjectAnimator anim = ObjectAnimator.ofFloat(text, "scaleY", 1f, 5f, 1f);  

        anim.setDuration(5000);  

        // 回调监听,可以有也可以无。  

        // 根据情况,如果需要监听动画执行到何种“进度”,那么就监听之。  

        anim.addUpdateListener(new AnimatorUpdateListener() {  

            @Override  

            public void onAnimationUpdate(ValueAnimator animation) {  

                float value = (Float) animation.getAnimatedValue();  

                Log.d("zhangphil", value + "");  

            }  

        });  

        // 正式开始启动执行动画  

        anim.start();  

    }

mRotateAnimat.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {
//                view.setVisibility(View.GONE);
view.clearAnimation();
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: