属性动画AnimatorDemo

/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/activity_main.xml

<?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="com.example.animatordemo.MainActivity">


    <TextView
        android:onClick="onClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <ImageView
        android:layout_marginTop="100dp"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/brad_pitt"
        android:id="@+id/cion"
        android:layout_width="150dp"
        android:layout_height="150dp" />


</LinearLayout>


/******************************************************************************************/styles.xml

<resources>


    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>


</resources>

/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/MainActivity 

package com.example.animatordemo;


import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity {


    private ImageView icon;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        icon = (ImageView) findViewById(R.id.cion);
    }


    public void onClick(View v) {


        //属性动画  ValueAnimator 的用法  ,属性动画本质是值动画
//        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f);
//        valueAnimator.setDuration(2000);
//        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                float animatedValue = (float) animation.getAnimatedValue();
//                Log.e("TAG", "=========== animatedValue == " + animatedValue);
//                ViewGroup.LayoutParams layoutParams = icon.getLayoutParams();
//                layoutParams.width = (int) (animatedValue*1000);
//                layoutParams.height = (int) (animatedValue*1000);
//                icon.setLayoutParams(layoutParams);
//            }
//        });
//        valueAnimator.start();




        //ObjectAnimator的用法


        //透明度变化
//        ObjectAnimator alphaObjectAnimator = ObjectAnimator.ofFloat(icon, "alpha", 0f, 1f, 0.5f);
//        alphaObjectAnimator.setDuration(2000)
//                .start();


//        ObjectAnimator scaleXObjectAnimator = ObjectAnimator.ofFloat(icon, "scaleX",0f,1f,0.5f);
//        scaleXObjectAnimator.setDuration(2000)
//                .start();


//        ObjectAnimator translationXObjectAnimator = ObjectAnimator.ofFloat(icon, "translationX",0f,1000f);
//        translationXObjectAnimator.setDuration(2000)
//                .start();


        ObjectAnimator rotationObjectAnimator = ObjectAnimator.ofFloat(icon, "rotation",0f,-360f);
        rotationObjectAnimator.setDuration(2000);
        rotationObjectAnimator.setRepeatCount(3);
        rotationObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
        rotationObjectAnimator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {


            }


            @Override
            public void onAnimationEnd(Animator animation) {


            }


            @Override
            public void onAnimationCancel(Animator animation) {


            }


            @Override
            public void onAnimationRepeat(Animator animation) {


            }
        });
        rotationObjectAnimator.start();




        //ViewPropertyAnimator的用法
//        icon.animate().alpha(0.5f)
//                .translationX(100f)
//                .rotation(180)
//                .scaleX(2)
//                .scaleY(2)
//                .setStartDelay(2000)
//                .setDuration(3000);
    }
}


/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/注册

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.animatordemo">


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值