android动画篇——动画加速器

android动画的加速器类Interpolator是用来描述动画运行时动画速率的快慢的类。

  • AccelerateDecelerateInterpolator
    An interpolator where the rate of change starts and ends slowly but accelerates through the middle.

  • AccelerateInterpolator*
    An interpolator where the rate of change starts out slowly and and then accelerates.

  • AnticipateInterpolator
    An interpolator where the change starts backward then flings forward.

  • BounceInterpolator
    - An interpolator where the change bounces at the end.*

  • DecelerateInterpolator
    An interpolator where the rate of change starts out quickly and and then decelerates.

  • LinearInterpolator
    An interpolator where the rate of change is constant

  • OvershootInterpolator
    An interpolator where the change flings forward and overshoots the last value then comes back.

实战:

  1. 在res文件夹下新建anim文件夹
  2. 在anim下新建animation.xml
  3. animation.xml源代码:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXDelta="0"
    android:toXDelta="100%"
    android:interpolator="@android:anim/anticipate_overshoot_interpolator" >

</translate>

布局文件activity_layout源代码:

<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.example.testactivity.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="27dp"
        android:text="移动" />

</RelativeLayout>

MainActivity源代码:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.button1).setOnClickListener(
                new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        Animation animation = AnimationUtils.loadAnimation(
                                MainActivity.this, R.anim.animation);
                        findViewById(R.id.textView1).startAnimation(animation);
                    }
                });
    }

}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值