动画示例

Posted loaderman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动画示例相关的知识,希望对你有一定的参考价值。

图片实现由由远到近的效果

     ImageView imageView = (ImageView)findViewById(R.id.frame_image);
        ScaleAnimation scaleAnim = new ScaleAnimation(1.0f,1.2f,1.0f,1.2f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);
        scaleAnim.setFillAfter(true);
        scaleAnim.setInterpolator(new BounceInterpolator());
        scaleAnim.setDuration(6000);
        scaleAnim.setRepeatMode(Animation.REVERSE);
        scaleAnim.setRepeatCount(Animation.INFINITE);//无限循环
        imageView.startAnimation(scaleAnim);

加载框动画

     ImageView imageView = (ImageView)findViewById(R.id.loading);

        RotateAnimation rotateAnim = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        rotateAnim.setRepeatCount(Animation.INFINITE);
        rotateAnim.setDuration(2000);
        rotateAnim.setInterpolator(new LinearInterpolator());
        imageView.startAnimation(rotateAnim);

扫描动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:duration="3000">
    <scale
            android:repeatCount="infinite"
            android:fromXScale="1.0"
            android:fromYScale="1.0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toXScale="3"
            android:toYScale="3"/>
    <alpha
            android:repeatCount="infinite" 
            android:fromAlpha="0.4"
            android:toAlpha="0"/>
</set>  
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.loaderman.customviewdemo.MainActivity">

    <ImageView
        android:id="@+id/circle1"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:src="@drawable/scan_cirle"/>

    <ImageView
        android:id="@+id/circle2"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:clickable="true"
        android:src="@drawable/scan_cirle"/>

    <ImageView
        android:id="@+id/circle3"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:clickable="true"
        android:src="@drawable/scan_cirle"/>

    <ImageView
        android:id="@+id/circle4"
        android:layout_width="140dp"
        android:layout_height="140dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:clickable="true"
        android:src="@drawable/scan_cirle"/>

    <TextView
        android:id="@+id/start_can"
        android:layout_width="155dp"
        android:layout_height="155dp"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:background="@drawable/scan_cover"/>


</FrameLayout>
package com.loaderman.customviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Animation animation1 = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale_alpha_anim);
        final Animation animation2 = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale_alpha_anim);
        final Animation animation3 = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale_alpha_anim);
        final Animation animation4 = AnimationUtils.loadAnimation(MainActivity.this,R.anim.scale_alpha_anim);

        final ImageView circle1 = (ImageView)findViewById(R.id.circle1);
        final ImageView circle2 = (ImageView)findViewById(R.id.circle2);
        final ImageView circle3 = (ImageView)findViewById(R.id.circle3);
        final ImageView circle4 = (ImageView)findViewById(R.id.circle4);

        findViewById(R.id.start_can).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                circle1.startAnimation(animation1);

                animation2.setStartOffset(600);//延迟动画开始时间
                circle2.startAnimation(animation2);

                animation3.setStartOffset(1200);
                circle3.startAnimation(animation3);

                animation4.setStartOffset(1800);
                circle4.startAnimation(animation4);
            }
        });

    }
}

效果:

技术分享图片

以上是关于动画示例的主要内容,如果未能解决你的问题,请参考以下文章

片段之间动画的共享元素

JavaScript-Tool-lhgDialog:动画示例

VSCode自定义代码片段——CSS动画

VSCode自定义代码片段7——CSS动画

VSCode自定义代码片段7——CSS动画

使用嵌套片段和动画对象