8

I use NineOldAndroids 2.4.0 to animate objects mainly for the movement and transformation of control. On Android 4.0 and above all works fine,but on previous versions (2.1, 2.3) after the animation elements do not receive focus and do not clickable. Sample code:

View v = findViewById(R.id.button1);
v.setOnClickListener(new OnClickListener() {

     @Override
     public void onClick(View v) {
        Toast.makeText(MainActivity.this, "Click!", Toast.LENGTH_SHORT).show();
     }
});
ObjectAnimator moveDown = ObjectAnimator.ofFloat(v, "translationY", 100f);
moveDown.setDuration(5000);
moveDown.start();

This is a bug in the library or something I'm doing wrong? If this library does not support all the functionality of "Honeycomb animation API", then in my project, it will be useless.

Quote on Android Developer Blog of "Animation in Honeycomb": Since the system is actually changing properties on target objects, the objects themselves are changed, not simply their appearance. So that button you move is actually moved, not just drawn in a different place. You can even click it in its animated location. Go ahead and click it; I dare you.

avesha
  • 136
  • 1
  • 6
  • The snippet you have works fine for me with NineOldAndroid on 2.3. Make sure you have imported the com.nineoldandroids.animation.ObjectAnimator and not android.animation.ObjectAnimator. – kirthika selvaraj Nov 02 '12 at 01:46
  • 1
    Yes, i imported the com.nineoldandroids.animation.ObjectAnimator. Are you sure that you can press on the button after move? As I said earlier, this is not working for <3.0, I tested it on the emulator: 2.1,2.2, 2.3.3 and on a real device (2.3.7) – avesha Nov 04 '12 at 20:55
  • I got the same problem. Did you try to use translateYBy() or x()? – Mario Dec 18 '12 at 18:14

1 Answers1

7

now i found the answer: How to do interactive animation (translation) with Android

it says that nineoldandroids got the same limitations as the native SDK.

so my solution:

myAnim.setListener(new AnimatorListenerAdapter() {
  @Override
  public void onAnimationEnd ( Animator nullPointer ) {
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) child.getLayoutParams();
    params.bottomMargin += toYDelta;
    params.leftMargin += toXDelta;
    child.setLayoutParams(params);
  }
});
Community
  • 1
  • 1
Mario
  • 758
  • 12
  • 25
  • 3
    Yes, this is a platform limitation. You need to physically move the view when the animation ends on pre-Honeycomb. – Jake Wharton Mar 28 '13 at 17:09
  • 2
    Note that changing a View's margins to reposition the View works well if the View is being moved **within** its parent, but if you need to reposition your View so that part of it is to move outside of its parent's bounding box, you could run into issues of your View being resized. – Adil Hussain Apr 18 '13 at 09:56