Search code examples
androidsliderandroid-animationandroid-4.0-ice-cream-sandwich

How to create an Animation with scrollTo Android


Is there any good (or not so good) solution to animate a RelativeLayout.scrollTo(x,y) method??

I have made a RelativeLayout which scrolls left/right simulating some gApps menu. It scrolls when dragging It left and right. Now what I want is to avoid this layout from being in the middle of Its way, and depending of where the user leaves the finger, the layout should go to the left or to the right with a kind of animation, but I can't find the right solution...

Any help would be appreciated. Thanks!


Solution

  • Definitively I moved to RelativeLayout.setTranslationX(float value).

    At that point, I had problems with TranslateAnimation() as It has a bug. As I have a minSdkVersion > 11, I can use ObjecAnimator as follows:

    ObjectAnimator objAnim = ObjectAnimator.ofFloat(view, "translationX", TARGET_TRANSLATE);
    objAnim.setDuration(200);
    objAnim.start();
    

    Thats a common problem so here is an answer =).