码迷,mamicode.com
首页 > 其他好文 > 详细

多种动画效果的结合使用方法以及Interpolator简介

时间:2016-03-28 01:56:24      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

Interpolator的两种用法属性

1.在xml中设置android:interpolator="@android:anim/accelerate_decelerate_interpolator"

2.在.java文件中设置,有两种情况

若设置为true,则统一interpolator速度;

AnimationSet animationSet = new AnimationSet(true);

若设置为false,则需要单独为各个动画设置interpolator

AnimationSet animationSet = new AnimationSet(false);
AlphaAnimation alpha = new AlphaAnimation(1.0f,0.0f);
RotateAnimation rotate = new RotateAnimation(0, 360, 
                    Animation.RELATIVE_TO_SELF, 0.5f, 
                    Animation.RELATIVE_TO_SELF, 0.5f);
alpha.setInterpolator(new AccelerateInterpolator());
rotate.setInterpolator(new AccelerateInterpolator());

alpha动画和rotate动画结合使用

MainActivity.java

public class MainActivity extends Activity {

    private Button button = null;
    private ImageView imageView = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        imageView = (ImageView)findViewById(R.id.imageViewId);
        button = (Button)findViewById(R.id.scaleButtonId);
        button.setOnClickListener(new AnimationButtonListener());
    }

    private class AnimationButtonListener implements OnClickListener {
        @Override
        public void onClick(View v) {
            /**
            Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);
            imageView.startAnimation(animation);
            */
            AnimationSet animationSet = new AnimationSet(true);
            AlphaAnimation alpha = new AlphaAnimation(1.0f,0.0f);
            RotateAnimation rotate = new RotateAnimation(0, 360, 
                    Animation.RELATIVE_TO_SELF, 0.5f, 
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animationSet.addAnimation(alpha);
            animationSet.addAnimation(rotate);
            animationSet.setDuration(2000);
            animationSet.setStartOffset(500);
            imageView.startAnimation(animationSet);
        }
    }
}

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.shen.animation04.MainActivity" >

    <Button 
        android:id="@+id/scaleButtonId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="测试动画效果"/>
    
    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView 
            android:id="@+id/imageViewId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="100dp"
            android:src="@drawable/ic_launcher"/>
    </LinearLayout>

</RelativeLayout>

group.xml(alpha&rotate)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:shareInterpolator="true">

    <alpha 
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:startOffset="500"
        android:duration="2000"/>
    
    <rotate 
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="2000"/>

</set>

 

多种动画效果的结合使用方法以及Interpolator简介

标签:

原文地址:http://www.cnblogs.com/shen-smile/p/5327486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!