Here’s my code that, upon a click of the “menu” button, slides ‘menubtm’ in or out of view. Is there a way to make it pause for a few milliseconds at every loop, so that it would be viable, how the menubtm moves?
Thanks!
@Override
public boolean onKeyDown(int keycode, KeyEvent event ) {
if(keycode == KeyEvent.KEYCODE_MENU){
if ( menuBtmVisable == true )
{
menuBtmVisable = false;
int xnow = menuBtmTopLimit;
while (xnow<menuBtmTopLimit+120)
{
xnow+=1;
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(480, 120, 0, xnow);
menubtm.setLayoutParams(lp);
}
}
else
{
menuBtmVisable = true;
int xnow = menuBtmTopLimit+120;
while (xnow>menuBtmTopLimit)
{
xnow-=1;
AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(480, 120, 0, xnow);
menubtm.setLayoutParams(lp);
}
}
}
return super.onKeyDown(keycode,event);
}
EDIT:
Thanks to your advice, I did it with animations.
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0"
android:toYDelta="120"
android:duration="500"
/>
This animation has to make the menu slide 120 px down… it does so ok, but then springs back into the old place. Is there a way to make it stay in the new location?
EDIT2 : got it!
android:fillEnabled="true"
android:fillAfter="true"
Instead of hacking it yourself, use Android Animations, which is designed exactly for this sort of thing. It will be much more stable and probably look much better in the end.