Note that there are some explanatory texts on larger screens.

plurals
  1. POView.getX/Y and View.setX/Y below Android 3.0
    text
    copied!<p>I am working on a project that must work on Android 2.2 onwards, and I just realized I was using a 3.0+ method from View.</p> <p>I have a menu that animates vertically sliding in/out when a button is pressed. When the animation finishes I update the View position with setY() method.</p> <p>I tried to change it to getTop/setTop but it's not working properly, I suspect because getY is actually taking into account transformations and getTop is not (I guess animations are handled as transformations).</p> <p>Any easy alternative for Froyo without modifying too much code?</p> <p>This is the animation part:</p> <pre><code> animationSlideInDown = AnimationUtils.loadAnimation(this, R.anim.slide_out_down); animationSlideOutUp = AnimationUtils.loadAnimation(this, R.anim.slide_in_up); animationSlideInDown.setDuration(200); animationSlideOutUp.setDuration(200); animationSlideInDown.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { if (menuInitialPosition == -1) { menuInitialPosition = menu.getY(); menuHeight = menu.getHeight(); } else { menu.setY(menuInitialPosition); } } @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { menu.setY(menuInitialPosition); } }); animationSlideOutUp.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { menu.setY(-menuHeight); } }); </code></pre> <p>This is the slide_out transition:</p> <pre><code>&lt;translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromYDelta="-100%" android:toYDelta="0" android:fillAfter="true" android:fillEnabled="true" android:duration="@android:integer/config_longAnimTime" /&gt; </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload