为了账号安全,请及时绑定邮箱和手机立即绑定

Android 安卓动画 属性动画 - 旋转动画

标签:
Java Android

引入

属性动画的出现,弥补了补间动画的不足之处,补间动画,只是改变了表面上的东西,但是其中属性并未改变,而属性动画相反,改变了表面上的东西,并且也更改了其属性。


类:ObjectAnimator

用于操作属性动画的类


动画 - 相关文章篇

帧动画

帧动画:  https://blog.csdn.net/qq_40881680/article/details/82222684


补间动画

补间动画-平移动画:  https://blog.csdn.net/qq_40881680/article/details/82255459

补间动画-缩放动画:  https://blog.csdn.net/qq_40881680/article/details/82260914

补间动画-旋转动画:  https://blog.csdn.net/qq_40881680/article/details/82261557

补间动画-透明/渐变动画:  https://blog.csdn.net/qq_40881680/article/details/82261869

补间动画-组合动画(四个动画一起播放):  https://blog.csdn.net/qq_40881680/article/details/82285987


属性动画

属性动画-渐变透明动画:  https://blog.csdn.net/qq_40881680/article/details/82318363

属性动画-旋转动画:  https://blog.csdn.net/qq_40881680/article/details/82354017

属性动画-缩放动画:  https://blog.csdn.net/qq_40881680/article/details/82377850

属性动画-移动动画:  https://blog.csdn.net/qq_40881680/article/details/82378391

属性动画-组合动画:  https://blog.csdn.net/qq_40881680/article/details/82381258


布局文件 篇

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#9c98ce"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="10dp">

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#5b7bda"
            android:text="点击演示动画"
            android:textColor="#fff" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:background="@mipmap/kuiba" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="《魁拔》"
            android:textSize="18sp" />

    </LinearLayout></LinearLayout>


代码逻辑 篇

属性动画用到的是:ObjectAnimator

package com.example.text.shuxingdonghua;import android.animation.ObjectAnimator;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    ObjectAnimator objectAnimator;    private Button button;    private ImageView image;    @Override
    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }    private void initView() {
        button = (Button) findViewById(R.id.button);
        image = (ImageView) findViewById(R.id.image);
        button.setOnClickListener(this);
        image.setOnClickListener(this);
    }    @Override
    public void onClick(View v) {        switch (v.getId()) {            case R.id.button:
                objectAnimator = ObjectAnimator.ofFloat(image,"rotation",360f);
                objectAnimator.setDuration(2000);
                objectAnimator.start();                break;            case R.id.image:
                Toast.makeText(this, "我是属性动画", Toast.LENGTH_SHORT).show();                break;
        }
    }
}

AndroidStudio快速实例化-插件安装与使用:https://blog.csdn.net/qq_40881680/article/details/82012180


objectAnimator = ObjectAnimator.ofFloat(image,"rotation",360f);

将图片旋转360度,只有一次效果


objectAnimator = ObjectAnimator.ofFloat(image,"rotation",0f,360f);

将图片,从初始值0度,顺时针转360度


objectAnimator = ObjectAnimator.ofFloat(image,"rotation",0f,360f,0f);

将图片,从初始0度,顺时针旋转360度,再逆时针旋转360度到0度


ObjectAnimator.ofFloat()括号中的参数:

第一个参数,要实现动画的控件id

第二个参数,要实现的动画属性,以下列出6种:  

propertyName

详细作用
alpha实现渐变效果
rotation实现旋转旋转效果
translationX实现水平移动效果(左或右移动)
translationY实现纵向移动效果(向上或者向下移动)
scaleX实现轴X缩放效果(放大或者缩小)
scaleY实现轴Y缩放效果(放大或者缩小)

后面的参数就不多做解释了,以上都有


效果演示 篇

第一种:将图片旋转360度

第二种:将图片,从初始值0度,顺时针转360度

第三种:将图片,从初始0度,顺时针旋转360度,再逆时针旋转360度到0度



点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消