在前几篇博客中讲述了如何使用视图动画和如何使用插值器以及自定义自己的插值器,在本篇博客中,我将向你讲述animator和animation的简单区别。属性动画与视图动画相比,存在哪些有点呢,首先视图动画能做的属性动画都可以做,而且可以做的的更好。在视图动画中,如果对一个button做移动动画,那么button的点击事件的有效点击区域并不会随着button的移动而发生改变,但是属性动画不一样,如果使用属性动画对button做移动动画,事件的点击区域会随着移动不断发生改变的。
详细情况还是看一下效果图吧:
可以很明显的看出,使用animator的时候,响应点击事件的有效区域也会发生改变。
现在看一下代码:
主布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
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"