Android动画效果总结(一)

本文详细介绍了Android中动画的实现方式,包括平移、旋转、缩放等常见动画效果,并通过具体的XML配置实例展示了如何设置动画参数。

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);

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值