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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 千兆以太网技术原理图_以太网和千兆口区别

    千兆以太网技术原理图_以太网和千兆口区别  1.1早期以太网技术  以太网:IEEE802.3定义了10Mbps的以太网标准,采用载波监听和冲突检测(CSMA/CD)协议,以半双工方式运行。从80年代末开始以太网取得了巨大的成功。10BaseT是运行在3类或更高类别的双绞线上的以太网,10Base2/5是运行在同轴电缆上的以太网,10BaseFL是运行在光纤上的以太网。由于冲突检测的协议要求一个512…

    2025年7月10日
    3
  • spring在LInux下出现的问题【转】

    spring在LInux下出现的问题【转】

    2022年3月2日
    38
  • import啥意思_import怎么导入

    import啥意思_import怎么导入前言我们在开发项目时经常会进行导包有import*格式的,还有from*import*格式的,最后就会显示的很乱,那么有没有什么工具能对导包进行一键排序呢?答案是有的,使用isort工具i

    2022年7月31日
    6
  • pycharm无法连接服务器_pycharm部署项目到服务器

    pycharm无法连接服务器_pycharm部署项目到服务器Pycharm连接服务器Pycharm连接服务器是最为常用的内容,本文记录了Pycharm连接服务器的方法。BlueStragglers分享技术成长的乐趣目录Pycharm连接服务器1.操作步骤1.1创建连接1.2新建项目1.3运行配置2.常见问题2.1不显示Package1.操作步骤1.1创建连接首先,需要创建连接。进入Tools→Deployment→Configuration,打开配置页面。在Deployment页面的Connection

    2022年8月29日
    5
  • linux目录结构详解_linux系统文件在哪个目录

    linux目录结构详解_linux系统文件在哪个目录前言平常linux系统用的也不少,那么linux下的每个目录都是用来干什么的,小伙伴们有仔细研究过吗?让我们来了解下吧Linux系统目录结构登录系统后,在当前命令窗口下输入命令:[root@

    2022年7月29日
    4
  • step by step学习LAMP配置

    step by step学习LAMP配置配置环境:debian6+apache+mysql+python步骤:1.在虚拟机上安装debian;2.配置虚拟机上网(采用host-only连接,单网卡,会虚拟出一个网卡,将主机的网络共享《 VMware下Linux网络配置攻略》,虚拟机和主机能够互相访问)3.配置debian,安装必要的软件包4.参考《http://library.linode.com/

    2022年6月6日
    36

发表回复

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

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