欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android Studio实现补间动画

程序员文章站 2022-06-18 13:29:52
本文实例为大家分享了android studio实现补间动画的具体代码,供大家参考,具体内容如下补间动画是给出初始位置和结束位置,中间由系统自动补充的动画1、补间动画的配置文件:scale.xml2、...

本文实例为大家分享了android studio实现补间动画的具体代码,供大家参考,具体内容如下

补间动画是给出初始位置和结束位置,中间由系统自动补充的动画

1、补间动画的配置文件:scale.xml

2、布局文件:animal_patching.xml

3、main.java

sacle.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:duration="3000"(运动时间)
        android:toyscale="0.5"(结束大小)
        android:toxscale="0.5"
        android:pivoty="50%"(运动中心位置)
        android:pivotx="50%"
        android:fromxscale="1"(初始大小)
        android:fromyscale="1"/>
</set>

animal_patching

<?xml version="1.0" encoding="utf-8"?>
<linearlayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <imageview
        android:id="@+id/image"
        android:background="@drawable/boy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</linearlayout>

main.java

package com.example.imageview;

import androidx.appcompat.app.appcompatactivity;

import android.os.bundle;
import android.view.view;
import android.view.animation.animation;
import android.view.animation.animationutils;
import android.widget.imageview;

public class mainactivity<i> extends appcompatactivity {
    /*
    private static final string tag = "leo";
    private notificationmanager manager;
    private notification notification;
    private popupwindow popupwindow;
    //创建一个数组,内部元素为bean类型;
    private list<bean> data = new arraylist<>();
     */
    private boolean flag = true;
    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.cartoon_patching);

        imageview imageview = findviewbyid(r.id.image);

        imageview.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view view) {
                //透明度***********************************
//                animation animation = animationutils.loadanimation(mainactivity.this,r.anim.alpad_1);
//                imageview.startanimation(animation);
                //旋转************************************
//                animation animation = animationutils.loadanimation(mainactivity.this,r.anim.rotate);
//                imageview.startanimation(animation);
                //大小缩放**********************************
//                animation animation = animationutils.loadanimation(mainactivity.this,r.anim.scale);
//                imageview.startanimation(animation);
                //平移************************************
                animation animation = animationutils.loadanimation(mainactivity.this,r.anim.translate);
                imageview.startanimation(animation);
            }
        });


}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。