android开发中animation详解,rotate,translate,alpha属性分析

本文详细解析Android中的两种动画效果——Tween Animation(包括AlphaAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation)和Frame Animation。通过XML定义动画,并在代码中加载和执行,实现视图的淡入淡出、旋转、缩放和平移效果。同时讨论了如何让控件在动画结束后保持在新位置并保持可交互性。
摘要由CSDN通过智能技术生成

在Android中,Animation有四种动画效果,并且分为Tween Animation和Frame Animation两类。

先看分类:

一、Tween Animation(补间动画)

一般我们用的就是这种。补间动画又分为AlphaAnimation(透明度转换)、RotateAnimation(旋转转换)、ScaleAnimation(缩放转换)、TranslateAnimation 位置转换(移动)。
动画效果在anim目录下的xml文件中定义,在程序中用AnimationUtils.loadAnimation(Context context,int ResourcesId)载入成Animation对象,在需要显示动画效果时,执行需要动画的View的startAnimation方法,传入Animation即可。切换Activity也可以应用动画效果,在startActivity方法后,执行overridePendingTransition方法,两个参数分别是切换前的动画效果,切换后的动画效果。


定义:

对一张图片进行一系列的变换(包括缩放、透明度、移动、旋转),对应的类是Animation;

在XML中实现动画的方法:

资源访问方式:

   In Java: R.anim.filename

     In XML: @[package:]anim/filename

文件位置:

    res/anim/filename.xml

语法:

filename.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
    <setxmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@[package:]anim/interpolator_resource"
        android:shareInterpolator=["true" | "false"] >
        <alpha
            android:fromAlpha="float"
            android:toAlpha="float"/>
        <scale
            android:fromXScale="float"
            android:toXScale="float"
            android:fromYScale="float"
            android:toYScale="float"
            android:pivotX="float"
            android:pivotY="float"/>
        <translate
            android:fromXDelta="float"
            android:toXDelta="float"
            android:fromYDelta="float"
            android:toYDelta="float"/>
        <rotate
            android:fromDegrees="float"
            android:toDegrees="float"
            android:pivotX="float"
            android:pivotY="float"/>
        <set>
            ...
        </set>
    </set>

详细说明:
set节点:对应AnimationSet类
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值