2

My Question Description

In this screenshot there are two ListViews.

enter image description here

What I want to achieve is when I touch the purple ListView, the touched cell will move up and stop at the position of bottom of the blue ListView.

For example, if I touched "Decision Heart Transplant", then their will be an animation showing this cell moves up, then stops at the position of "Liver Transplant".

What I Have Tried

I have tried this in the purple ListView

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {


        // Setup the animation view

        Log.d("onListItemClick", "Position: " + viewForAnim.getX() + ", " + viewForAnim.getY());

        // Move up the selected view
        Animation animation = null;

        animation = new TranslateAnimation(0, 0, 0, -v.getY()-l.getY());
        animation.setDuration(700);
        v.startAnimation(animation);
}

But this seemed will move the selected cell within the listview's bound, it can't move out of it.

Thinking that the animated purple listview's cell might be covered by the blue listview, I even tried change the listview's z-order by using

l.bringToFront();

However that didn't work either.

and I also tried the approach showed in this SO Post

Android -- How to position View off-screen?

it might work well for animating a view, but that didn't work for my case.

Then I tried setting the android:clipChildren and that didn't work for the animation that requires moving cell out of listview.

So could you guys point me a right way how to achieve this animation effect?

Community
  • 1
  • 1
dumbfingers
  • 7,001
  • 5
  • 54
  • 80

1 Answers1

1

try using relative_to_parent in translate animation

shreyas
  • 2,166
  • 3
  • 18
  • 30
  • thx, I've just tried by using `animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_PARENT, -100);` even the movement is set to -100, the animation for me is the touched cell just disappears, no moving animations at all. Could you point out which example should I look into? – dumbfingers Jul 19 '13 at 10:57
  • in the com.example.android.apis.view package look at the layoutanimation class... – shreyas Jul 19 '13 at 11:52
  • thx, I forgot to mention that I've tried the `LayoutAnimations` in my code before and it seemed not suit for my case. – dumbfingers Jul 19 '13 at 12:09