长按时摇动图标[编辑模式]

发布于 2024-12-21 20:50:01 字数 160 浏览 1 评论 0原文

我有一个带有一些 ImageButtons 的 Android 应用程序,就像图标一样。

我想知道如何实现用户长按图标后“摇动”图标的功能。就像编辑模式下的 iPhone 图标一样,你知道吗?

编辑完成后,图标不再晃动。

在 Android 中可以这样做吗?

I have an Android application with some ImageButtons, just like icons.

I would like to know how I could implement a function to "shake" icons after user long-presses them. Like iPhone icons on edit mode, you know?

After editing, icons stop shaking.

Is it possible to do that in Android?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

通知家属抬走 2024-12-28 20:50:01

使用它可以在长按按钮事件时在图标上启动摇动动画

public void onClick(View v) {
    Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
    findViewById(R.id.pw).startAnimation(shake);
}

此片段取自此处的 android API 演示 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Animation1.html

use this to start the shaking animation on your icons upon the long press event of your button

public void onClick(View v) {
    Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
    findViewById(R.id.pw).startAnimation(shake);
}

This snippet is taking from the android API Demo here http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Animation1.html

毁梦 2024-12-28 20:50:01

尝试在按钮上使用 TranslateAnimation(和/或 AnimationSet)。

像这样的东西:

private void onYourButtonLongPress()
{
    TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0);
    animation.setDuration(100):
    yourButton.startAnimation(animation);
}

请注意,此示例仅适用于向左摇动

Try to use TranslateAnimation (And/Or AnimationSet) on the button.

something like this:

private void onYourButtonLongPress()
{
    TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0);
    animation.setDuration(100):
    yourButton.startAnimation(animation);
}

notice that this example is only for shake to left

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文