【Android动画九章】-RotateAnimation(旋转动画)和ScaleAnimation(尺寸动画)

本文详细介绍了 Android 中的旋转动画 RotateAnimation 和尺寸动画 ScaleAnimation,包括它们的构造方法、参数解释以及代码和XML方式的实现示例。通过实例演示了如何改变视图的旋转角度和尺寸大小,并提供了完整的代码实现。
摘要由CSDN通过智能技术生成

public abstract class
Animation
extends Object
implements Cloneable
java.lang.Object
↳ android.view.animation.Animation
Known Direct Subclasses
AlphaAnimation, AnimationSet, RotateAnimation, ScaleAnimation, TranslateAnimation
同AlphaAnimation和TranslateAnimation一样,RotateAnimation和ScaleAnimation动画也都是Animation类的子类。这里一起进行介绍。

RotateAnimation

常用构造方法:
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)

fromDegrees:起始角度值
toDegrees: 结束角度值
pivotXType: 转动点X轴的转动标准,共三种,RELATIVE_TO_SELF 以自己为标准,RELATIVE_TO_PARENT以父组件为标准,ABSOLUTE表示绝对位置。
pivotXValue: 针对上面标准的值,取值0-1之间。
pivotYType: 转动点Y轴的转动标准,也是三种,RELATIVE_TO_SELF 以自己为标准,RELATIVE_TO_PARENT以父组件为标准,ABSOLUTE表示绝对位置。
pivotYValue: 针对上面标准的值,取值0-1之间。
下面通过一个实例进行演示:

代码方式实现

1.主布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context="demo.androidwar.com.translatedemo.MainActivity">

    <Button
        android:id="@+id/btn_rotate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="center"
        android:onClick="rotate"
        android:text="旋转动画"
        android:textSize="20sp" />

    <ImageView

        android:layout_gravity="center"
        android:id="@+id/imgview"
        android:layout_width
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值