在Android的按钮动画 [英] Button animations in android

查看:126
本文介绍了在Android的按钮动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,大家好!

今天我得到了,因为我想,很有意思的问题。 在我的工作,我们正在创建一个约会服务的主要特点之一将是在屏幕上,在那里的照片不同的女孩(或人)的显示,用户preSS无论是热或不是按钮。这两个按钮下方显示在屏幕上的照片。 我们的分析说,(神保佑他们......),我们应该实施某种形式的游戏机制,所以希望这样的事情:当用户preSS,例如,而不是按钮 - 它开始冻结覆盖有冰,然后它打破,然后下一张照片显示。那不是缩放或旋转或平移的动画...按钮本身,其godb​​lessed的内容应万变了一些小的一段时间(一两秒钟也许)。 这让我害怕了很多,当我想在不同的设备,不同的烦恼与ninepatch和手工制作的帧动画缩放这些按钮,我是(因为它看起来像)将会使的原因 - 我想哭......

请告诉我,我需要你的专长 - 是不是真的做出这样的事情???或者,也许有任何解决方法或什么...

请,我几乎恐慌...

解决方案
  1. 请图像,动画,并保持一个文件夹中的PNG格式。
  2. 在动画低于code的图像。

 <动画列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:单稳=真正的>
 <项目机器人:可绘制=@可绘制/ rocket_thrust1机器人:时间=200/>
 <项目机器人:可绘制=@可绘制/ rocket_thrust2机器人:时间=200/>
 <项目机器人:可绘制=@可绘制/ rocket_thrust3机器人:时间=200/>
 < /动画列表>
 

然后

  AnimationDrawable rocketAnimation;

公共无效的onCreate(包savedInstanceState){
  super.onCreate(savedInstanceState);
  的setContentView(R.layout.main);

  ImageView的rocketImage =(ImageView的)findViewById(R.id.rocket_image);
  rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
  rocketAnimation =(AnimationDrawable)rocketImage.getBackground();
}

公共布尔的onTouchEvent(MotionEvent事件){
  如果(event.getAction()== MotionEvent.ACTION_DOWN){
    rocketAnimation.start();
    返回true;
  }
  返回super.onTouchEvent(事件);
}
 

Good day, everyone!

Today I got, as I suppose, very interesting question. On my job we are creating a dating service and one of the main features will be the screen, where photos of different girls( or guys) are shown and the user press either "Hot" or "Not" button. Both of these buttons are displayed below the photo on the screen. Our analytics say (god "bless" them...) that we should implement some kind of "gaming" mechanics, so the want such a thing: when user press, for example, "Not" button - it starts freezing and covering with ice, then it breaks and then the next photo is shown. That is not scale or rotate or translate animation... the button itself, its "godblessed" content should be changing over some small period of time (a second or two maybe). That scares me alot, cause when I'm thinking about scaling these buttons on different devices, and different troubles with ninepatch and hand-made-frames animations I' m (as it looks like) going to make - I want to cry...

Tell me please, I need your expertise - is it really to make such thing??? Or maybe there are any kind of workarounds or something...

Please, I'm nearly panic...

解决方案

  1. Make images for your animation and keep in a folder in png format.
  2. Animate those images with code below.

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="true">
 <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
 <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
 <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
 </animation-list>

Then

AnimationDrawable rocketAnimation;

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
  rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
  rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
}

public boolean onTouchEvent(MotionEvent event) {
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
    rocketAnimation.start();
    return true;
  }
  return super.onTouchEvent(event);
}

这篇关于在Android的按钮动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆