我有一个Android应用程序,里面有一些ImageButtons,就像图标一样。
我想知道如何实现一个功能,以"摇"图标后,用户长按他们。就像iPhone编辑模式下的图标?
编辑完成后,图标停止晃动
有可能在Android中做到这一点吗?
使用此参数在按钮长按事件时启动图标的抖动动画
public void onClick(View v) {
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
findViewById(R.id.pw).startAnimation(shake);
}
这个片段取自android API Demo http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/Animation1.html
尝试在按钮上使用TranslateAnimation (And/Or AnimationSet)
像这样:
private void onYourButtonLongPress()
{
TranslateAnimation animation = new TranslateAnimation(0, -5, 0, 0);
animation.setDuration(100):
yourButton.startAnimation(animation);
}
注意,这个例子只适用于左摇