Android动画效果总结(一)
100%p的意思是:当前控件的左上角+父控件/布局宽度的100%
50% 的意思是:当前控件的左上角+当前控件的50%
50 的意思是:当前控件的左上角+50px
平移translate:
android:fromYDelta=”100%p”:起始位置y坐标为“当前控件的左上角+父控件/布局宽度的100%”
toYDelta:结束位置y坐标
旋转rotate:
fromDegrees=”0”:开始角度为 0°
pivotX=”50%” :旋转圆心为 x轴方向“当前控件的左上角+当前控件的50%”
缩放 Scale:
fromXScale=”0.0”:开始时,控件x轴大小为0
toXScale=”0.8”:结束时,控件大小为0.8倍的控件(x轴方向)
fromYScale=”1”:y方向,控件大小不变
toYScale=”1”
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--平移-->
<!--<translate-->
<!--android:duration="1000"-->
<!--android:fromYDelta="100%p"-->
<!--android:toYDelta="0%p"-->
<!--android:repeatCount="1000000"-->
<!--android:repeatMode="reverse"-->
<!--/>-->
<!--绕着圆心转圈圈-->
<!--<rotate-->
<!--android:duration="1000"-->
<!--android:fromDegrees="0"-->
<!--android:toDegrees="360"-->
<!--android:pivotX="50%"-->
<!--android:pivotY="50%"-->
<!--android:repeatCount="1000000"-->
<!--android:repeatMode="restart"-->
<!--/>-->
<!--透明度变化 -->
<!--<alpha-->
<!--android:repeatCount="1000000"-->
<!--android:duration="1000"-->
<!--android:fromAlpha="0"-->
<!--android:toAlpha="1.0"-->
<!--/>-->
<!--x方向上相对自身缩放的比例-->
<scale
android:fromXScale="0.0"
android:toXScale="0.8"
android:fromYScale="1"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="10000"
android:repeatCount="1000000"/>
</set>
activity的xml文件为
<?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"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.story.myapplication.MainActivity">
<LinearLayout
android:background="@color/colorAccent"
android:layout_width="300dp"
android:layout_height="300dp">
<TextView
android:id="@+id/text_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#33333"
android:text="Hello World!" />
</LinearLayout>
</RelativeLayout>
activity的代码为
> package com.story.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.text_1);
Animation animation = AnimationUtils.loadAnimation(this,R.anim.animation_translate);
textView.setAnimation(animation);
}
}