【问题标题】:Move button randomly on screen android在屏幕android上随机移动按钮
【发布时间】:2013-06-26 05:03:25
【问题描述】:

我是 android 开发的新手。我想在屏幕上有一个可以连续移动的按钮。当它接触到侧面时,它应该会反弹回来。点击时会打开活动。我该怎么做呢?任何有用的链接?想法?谢谢!

【问题讨论】:

  • 在提问之前尝试过什么?请描述你的努力。
  • 启发from here.

标签: android button move


【解决方案1】:

对于移动按钮,您需要使用动画 这是它的片段

TranslateAnimation  mAnimation = new TranslateAnimation(
                            TranslateAnimation.RELATIVE_TO_PARENT, 1f,
                            TranslateAnimation.RELATIVE_TO_PARENT, -1.2f,
                            TranslateAnimation.ABSOLUTE, 0f,
                            TranslateAnimation.ABSOLUTE, 0f
                           );
                   mAnimation.setDuration(15000);
                   mAnimation.setRepeatCount(-1);
                   mAnimation.setRepeatMode(Animation.INFINITE);
                   mAnimation.setInterpolator(new LinearInterpolator());
                   mAnimation.setFillAfter(true);

                    LinearLayout alertlayout = (LinearLayout) findViewById(R.id.alertll);
                    alertlayout.startAnimation(mAnimation);

以及打开一个新活动

Intent intent = new Intent(YourActivity.this,NewActivity.class);
StartActivity(intent);

【讨论】:

  • 您介意解释一下设置重复计数的作用吗?这将如何随机移动?非常感谢!
  • 另外,这会反弹吗?
  • 现在有更复杂的库可用...尝试使用它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-15
  • 1970-01-01
相关资源
最近更新 更多