android代码实现ScaleAnimation[通俗易懂]

android代码实现ScaleAnimation[通俗易懂]packagecom.yangguangfu.cn;importandroid.app.Activity;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.animation.Animation;importandroid…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

package com.yangguangfu.cn;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.Animation.AnimationListener;

import android.view.animation.ScaleAnimation;

import android.widget.ImageView;

public class ScaleAnimationDemoActivity extends Activity implements

        OnClickListener {

    private ImageView top_left;

    private ImageView top_right;

    private ImageView bottom_left;

    private ImageView bottom_right;

    private ImageView center;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) { // 要使用findViewById,

        super.onCreate(savedInstanceState); // 做为使用者介面

        setContentView(R.layout.second);

        // 取得UI 介面中的View 物件

        // 取得View 物件后,再透过转换成实际的物件

        top_left = (ImageView) findViewById(R.id.top_left);

        top_right = (ImageView) findViewById(R.id.top_right);

        bottom_left = (ImageView) findViewById(R.id.bottom_left);

        bottom_right = (ImageView) findViewById(R.id.bottom_right);

        center = (ImageView) findViewById(R.id.center);

        top_left.setOnClickListener(this);

        top_right.setOnClickListener(this);

        bottom_left.setOnClickListener(this);

        bottom_right.setOnClickListener(this);

        center.setOnClickListener(this);

    }

    @Override

    public void onClick(View v) {

        switch (v.getId()) {

        case R.id.top_left:

            topLeftScaleAnimation(v);

            break;

        case R.id.top_right:

            topRightScaleAnimation(v);

            break;

        case R.id.bottom_left:

            bottomLiftScaleAnimation(v);

            break;

        case R.id.bottom_right:

            bottomRightScaleAnimation(v);

            break;

        case R.id.center:

            centerScaleAnimation(v);

            break;

        }

    }

    private Animation topLeftanimation;

    private boolean istopLeft = false;

    private void topLeftScaleAnimation(final View v) {

        if (!istopLeft) {

            topLeftanimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f);

            istopLeft = true;

        } else {

            topLeftanimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f);

            istopLeft = false;

        }

        // 动画开始到结束的执行时间(1000 = 1 秒)

        topLeftanimation.setDuration(2000);

        // 动画重复次数(-1 表示一直重复)

        // am.setRepeatCount(1);

        topLeftanimation.setAnimationListener(new AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                top_left.setEnabled(true);

            }

        });

        topLeftanimation.setFillAfter(true);

        // 图片配置动画

        top_left.setAnimation(topLeftanimation);

        // Help();

        // handler.sendEmptyMessageDelayed(topHand, 2000);

        // top_left.setLayoutParams(lp);

        // 动画开始

        topLeftanimation.startNow();

        top_left.setEnabled(false);

    }

    private static final int topHand = 6;

    private boolean isBottomLift = false;

    Animation bottomLiftScaleAnimation = null;

    private void bottomLiftScaleAnimation(View v) {

        if (!isBottomLift) {

            bottomLiftScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f,

                    4.0f, Animation.RELATIVE_TO_SELF, 0f,

                    Animation.RELATIVE_TO_SELF, 1.0f);

            isBottomLift = true;

        } else {

            bottomLiftScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f,

                    1.0f, Animation.RELATIVE_TO_SELF, 0f,

                    Animation.RELATIVE_TO_SELF, 1.0f);

            isBottomLift = false;

        }

        // 动画开始到结束的执行时间(1000 = 1 秒)

        bottomLiftScaleAnimation.setDuration(2000);

        // 动画重复次数(-1 表示一直重复)

        // bottomLiftScaleAnimation.setRepeatCount(-1);

        bottomLiftScaleAnimation.setFillAfter(true);

        // 图片配置动画

        bottom_left.setAnimation(bottomLiftScaleAnimation);

        bottomLiftScaleAnimation.setAnimationListener(new AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                bottom_left.setEnabled(true);

            }

        });

        // 动画开始

        bottomLiftScaleAnimation.startNow();

        bottom_left.setEnabled(false);

    }

    private boolean isBottomRigth = false;

    Animation bottomRightScaleAnimation;

    private void bottomRightScaleAnimation(View v) {

        if (!isBottomRigth) {

            bottomRightScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f,

                    4.0f, Animation.RELATIVE_TO_SELF, 1.0f,

                    Animation.RELATIVE_TO_SELF, 1.0f);

            isBottomRigth = true;

        } else {

            bottomRightScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f,

                    1.0f, Animation.RELATIVE_TO_SELF, 1.0f,

                    Animation.RELATIVE_TO_SELF, 1.0f);

            isBottomRigth = false;

        }

        // 动画开始到结束的执行时间(1000 = 1 秒)

        bottomRightScaleAnimation.setDuration(2000);

        bottomRightScaleAnimation.setAnimationListener(new AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                // TODO Auto-generated method stub

                bottom_right.setEnabled(true);

            }

        });

        // 动画重复次数(-1 表示一直重复)

        // bottomRightScaleAnimation.setRepeatCount(-1);

        bottomRightScaleAnimation.setFillAfter(true);

        // 图片配置动画

        bottom_right.setAnimation(bottomRightScaleAnimation);

        // 动画开始

        bottomRightScaleAnimation.startNow();

        bottom_right.setEnabled(false);

    }

    private Animation topRightScaleAnimation;

    private boolean isTopRight = false;

    private void topRightScaleAnimation(View v) {

        if (!isTopRight) {

            topRightScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,

                    Animation.RELATIVE_TO_SELF, 1.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f);

            isTopRight = true;

        } else {

            topRightScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,

                    Animation.RELATIVE_TO_SELF, 1.0f,

                    Animation.RELATIVE_TO_SELF, 0.0f);

            isTopRight = false;

        }

        topRightScaleAnimation.setDuration(2000);
集装箱运费

        // 动画重复次数(-1 表示一直重复)

        // topRightScaleAnimation.setRepeatCount(-1);

        // 图片配置动画

        top_right.setAnimation(topRightScaleAnimation);

        topRightScaleAnimation.setAnimationListener(new AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                top_right.setEnabled(true);

            }

        });

        // 动画开始

        topRightScaleAnimation.startNow();

        topRightScaleAnimation.setFillAfter(true);

        top_right.setEnabled(false);

    }

    private boolean isCenter = false;

    Animation centerScaleAnimation;

    private void centerScaleAnimation(View v) {

        if (!isCenter) {

            centerScaleAnimation = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f,

                    Animation.RELATIVE_TO_SELF, 0.5f,

                    Animation.RELATIVE_TO_SELF, 0.5f);

            isCenter = true;

        } else {

            centerScaleAnimation = new ScaleAnimation(4.0f, 1.0f, 4.0f, 1.0f,

                    Animation.RELATIVE_TO_SELF, 0.5f,

                    Animation.RELATIVE_TO_SELF, 0.5f);

            isCenter = false;

        }

        centerScaleAnimation.setDuration(2000);

        centerScaleAnimation.setFillAfter(true);

        // 动画重复次数(-1 表示一直重复)

        // centerScaleAnimation.setRepeatCount(-1);

        centerScaleAnimation.setAnimationListener(new AnimationListener() {

            @Override

            public void onAnimationStart(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationRepeat(Animation animation) {

                // TODO Auto-generated method stub

            }

            @Override

            public void onAnimationEnd(Animation animation) {

                center.setEnabled(true);

                // TODO Auto-generated method stub

            }

        });

        // 图片配置动画
喝咖啡的英文翻译,喝咖啡的造句

        center.setAnimation(centerScaleAnimation);

        // 动画开始

        centerScaleAnimation.startNow();

        center.setEnabled(false);

    }

}

转载于:https://www.cnblogs.com/sky7034/archive/2011/06/22/2086594.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181543.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 分享一份软件测试项目实战(web+app+h5+小程序)

    分享一份软件测试项目实战(web+app+h5+小程序)大家好,我是谭叔。本次,谭叔再度出马,给大家找了一个非常适合练手的软件测试项目,此项目涵盖web端、app端、h5端、小程序端,可以说非常之全面。缘起在这之前,谭叔已经推出了九套实战教程。但是,这些教程以web测试和接口测试为主,没有app等项目。为了让实战项目更加全面、涵盖到各端,同时也为了满足读者粉丝们对项目的高需求,我决定再给大家找一个项目。(实力宠粉,求个赞不过分吧~)说实话,在找项目的过程中,我下载过(甚至付费下载过)N多个项目、联系过很多项目的作者,但是绝大部分项目,在我看来,并不

    2022年6月22日
    39
  • 使用SpringBoot连接MySQL数据库,快速上手「建议收藏」

    使用SpringBoot连接MySQL数据库,快速上手「建议收藏」使用SpringBoot连接MySQL数据库,快速上手

    2022年6月25日
    55
  • Python3网络爬虫快速入门实战解析

    Python3网络爬虫快速入门实战解析请在电脑的陪同下,阅读本文。本文以实战为主,阅读过程如稍有不适,还望多加练习。本文的实战内容有:网络小说下载(静态网站)、优美壁纸下载(动态网站)、爱奇艺VIP视频下载PS:本文为Gitchat线上分享文章,该文章发布时间为2017年09月19日。

    2022年6月12日
    29
  • 100道最新Java面试题,常见面试题及答案汇总

    除了掌握扎实的专业技能之外,你还需要一份《Java程序员面试宝典》才能在万千面试者中杀出重围,成功拿下offer。小编特意整理了100道Java面试题,送给大家,希望大家都能顺利通过面试,拿下高薪。赶紧码住吧~~Q1:Java内部类和子类之间有什么区别?答案:内部类是指在一个外部类的内部再定义一个类,内部类对外部类有访问权限,可以访问类中定义的所有变量和方法。子类是从父类(superclass)中继承的类,子类可以访问父类所有public和protected的字段和方法。Q2:Java语言中有哪些

    2022年4月16日
    120
  • Platform Device and Drivers

    Platform Device and DriversPlatformDeviceandDrivers从我们可以了解Platformbus上面的驱动模型接口:platform_device,platform_driver。和PCI和USB这些大结构的总线不同,虚拟总线Platformbus使用最小结构来集成SOCpro

    2022年7月24日
    8
  • php+mysql动态网站开发案例课堂_用php写一个网页页面

    php+mysql动态网站开发案例课堂_用php写一个网页页面在这篇文章中,我尽量用最浅显易懂的语言来说明使用PHP,MySQL制作一个动态网站的基本技术。阅读本文需要简单的HTML基础知识和(任一编程语言的)编程基础知识(例如变量、值、循环、语句块的

    2022年8月6日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号