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


相关推荐

  • Android SDK下载和安装,以及部署「建议收藏」

    Android SDK下载和安装,以及部署「建议收藏」第一步:先到网站地址下载资源下载地址:https://www.androiddevtools.cn/第二步:选择具体版本资源下载第三步:点击启动安装SDKManager.exe选择相应的工具包进行下载对于扩展选项:这里建议全选分别选中每个License,分别设置为AcceptLicense[这样更方便快捷!!]确认好都勾选后,点击Install下载注意:下载可能比较慢,耗费时间长,最重要的是保证网络好,没下载成功,就重进重选重新下载…

    2022年7月19日
    16
  • 海量数据处理思路「建议收藏」

    海量数据处理思路「建议收藏」海量数据处理思路海量数据处理海量数据,不能一次加载到内存中海量数据topK(最大和最小k个数),第k大,第k小的数海量数据判断一个整数是否存在其中海量数据找出不重复的数字找出A,B两个海量url文件中共同的url海量数据topK最大K使用最小堆,最小K使用最大堆,这里以最大K为例海量数据hash分块维护最小堆的K个数据的数据容器堆中数据是topK大的数据,堆顶的数据是第K大数据先将海量数据hash再取模m,分成m个小文件,hash(num)%m,也可以直接取模在

    2022年6月23日
    18
  • vb程序设计教程第4版龚沛曾 实验答案解析

    vb程序设计教程第4版龚沛曾 实验答案解析这里只是个人对书中题目的解答,并不代表最优代码。仅供参考。有哪里错误或者不足的地方还望指出,Thanks♪(・ω・)ノ以及不要脸地求探讨求点赞。嘿嘿这里使用的是《vb程序设计教程(第四版)——龚沛曾》:实验3(主要考察分支选择结构。1—7考察select和if语句,8用到choose函数,9—11以控件option和check为主)3.1:OptionExpl…

    2022年10月7日
    0
  • .NET设计模式(11):组合模式(Composite Pattern)

    .NET设计模式(11):组合模式(Composite Pattern)

    2021年7月22日
    64
  • ios个人开发者账号购买_马斯克回应推特收认证费用

    ios个人开发者账号购买_马斯克回应推特收认证费用原文网址:http://blog.sina.com.cn/s/blog_134451adb0102w152.html第一步:注册appleID登录https://developer.apple.com,选择MemberCenter​ ​填写邮箱地址(作为AppleID)、密码、名、姓(⚠️不要填反了。。。)、生日​

    2025年6月2日
    0
  • 人工智能猴子摘香蕉代码_猴子妈妈有14个香蕉

    人工智能猴子摘香蕉代码_猴子妈妈有14个香蕉只有简单的状态显示#include"iostream"usingnamespacestd;voidAT(charmonkeyplace,charboxplace){cout<<"AT(monkey,"<<monkeyplace<<")"<<endl;cout<&

    2022年9月26日
    0

发表回复

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

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