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


相关推荐

  • s一般怎么称呼自己的m_“老公、老婆、亲爱的”?快来围观明星怎么称呼自己的另一半!…

    s一般怎么称呼自己的m_“老公、老婆、亲爱的”?快来围观明星怎么称呼自己的另一半!…每个夫妻相处方法不一样,大家怎么称呼习惯就怎么来,官方上会跟别人介绍,我的爱人,我的对象,我的老公,私下也会亲昵的叫baby。今天我们就来说说明星们是怎么称呼自己的另一半的!黄晓明和baby,在家里的时侯,黄晓明就叫baby为小孩儿,听起来是否是就有种自愿吃狗粮的感到?大家都知道,黄晓明是很喜好baby的,对baby也很宠爱,大家说baby演技欠好,黄晓明还赶忙着帮baby措辞。小编记得当初他们两…

    2022年6月23日
    81
  • TCP报文段详解

    TCP协议tcp报文段源端口&目的端口2字节(tcp的分用功能以端口实现)序号4字节tcp三次握手中的seq,表示tcp数据段发送的第一个字节的序号,范围[0,2^32-1],即mod2^32;例如,seq=201,携带的数据有100,那么最后一个字节的序号就为300,那么下一个报文段就应该从401开始,下一个序列的首地址.tcp是面向字节…

    2022年4月7日
    61
  • partprobe命令学习「建议收藏」

    partprobe命令学习「建议收藏」partprobe是一个可以修改kernel中分区表的工具。可以使kernel重新读取分区表。如下命令可以查看你的系统是否安装了parted软件包rpm-qparted举例来说:#rpm-qpartedparted-1.6.3-29你可以使用up2date命令安装这个软件包,如果在你的系统已经正确地注册到RHN上了。否则你可以从光盘上安装这个文件。…

    2022年10月20日
    3
  • 三极管驱动继电器电路

    三极管驱动继电器电路    继电器线圈需要流过较大的电流(约50mA)才能使继电器吸合,一般的集成电路不能提供这样大的电流,因此必须进行扩流,即驱动。图1所示为用NPN型三极管驱动继电器的电路图,图中阴影部分为继电器电路,继电器线圈作为集电极负载而接到集电极和正电源之间。当输入为0V时,三极管截止,继电器线圈无电流流过,则继电器释放(OFF);相反,当输入为+VCC时,三极管饱和,继电器线圈有相当的电流流过,…

    2022年6月24日
    26
  • 何不给你单调的鼠标指针换一个好看的样式?(Windows系统下)

    鼠标指针是我们日常操控电脑最基本的工具,用久了难免会有些单调。换一个更好看或更炫酷的皮肤,或许会给你带来不一样的心情!这是我新换的鼠标指针样式,是不是很有意思。访问这个网站:点击跳转里面有几百种鼠标指针美化包。选好你喜欢的美化包后,点击下载。将下载好的安装包解压。里面有一个.inf文件。右键点击安装遇到下面这个,确定即可。安装完成后,右击鼠标选择个性化,主…

    2022年4月12日
    57
  • Pycharm最简单安装Python里面的各种包

    Pycharm最简单安装Python里面的各种包大家在用Pycharm安装各种Python里面的包时,可能会出错,安装不成功。下面我介绍一种最可靠,最稳定,最便利的安装。第一步:打开Pycharm,点击右上角的File,找到setting第二步:在setting里面搜索interpreter,找到ProjectInterpreter点击右侧的+号第三步:点击最下面的ManageRespositories删除默认的配置…

    2022年8月29日
    2

发表回复

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

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