1

I'm trying to animate a transition but it's not giving me the correct results

I have a layout that looks like this:

  • LinearView Root
    • ScrollView Groups
      • LinearView
        • Tile1
        • Tile2
        • Tile3
    • ScrollView SubGroups
      • LinearView
        • Tile4
        • Tile5
        • Tile6

Root's orientation is set to horizontal and both Groups and SubGroups has a width and height set to parent fill.

What I want is to animate Groups translating to the left out of the screen so that only ~40 dp is still showing, and SubGroups translating to left right behind Groups, so that only a sliver of Groups is shown and 90% of SubGroups is visible.

Is this possible? Thanks for any help!

joe_coolish
  • 7,201
  • 13
  • 64
  • 111

1 Answers1

5

i think you mean to do like this :

TranslateAnimation animateGroups = new TranslateAnimation(0,widthScreen - 40 , 0 , 0);
animateGroups.setDuration(1200);
animateGroups.setFillAfter(true);

TranslateAnimation animateSubGroups = new TranslateAnimation(0,widthScreen - 10 , 0 , 0);
animateSubGroups.setDuration(1200);
animateSubGroups.setFillAfter(true);

scrollViewGroups.startAnimation(animateGroups);
scrollViewSubGroups.startAnimation(animateSubGroups);

Note : you can get the screen Dimensions by using DiplayMetrics class , and if you want to convert the pixels to dp , refer this

EDIT : Change the place of your Views after the Animation end to do this , you should add a Listener On your animation ,

animateGroups.addAnimationListener(AnimationListener);

and override the method like this :

 @Override
 public void onAnimationEnd(Animation animation){
scrollViewGroups.setPadding(0, 0 , screenWidth-40 , 0 ) ;
//or you can set the Margin like this(i supposed that your scrollView is in a RelativeLayout 
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)scrollViewGroups.getLayoutParams();
params.setMargin(0, 0 , screenWidth-40 , 0);
scrollViewGroups.setLayoutParams(params);
}
Community
  • 1
  • 1
Houcine
  • 24,001
  • 13
  • 56
  • 83
  • Thank you for the animation! I have 2 questions though, after the animation has ran, the first group (the one moving off the screen) is correct, but the second group (the SubGroup) isn't displaying at all? Is there something I need to do to set the visibility to true? Also, after the animation has finished, I'm noticing that click coordinates don't reflect the translation. E.g., one of my buttons is able to be clicked by clicking where is was before the animation played and not its new location. Thank you for any more help you can provide :) – joe_coolish May 25 '11 at 23:59
  • we are here to help ; about the animation ,it's just an effect that's all , and when i setFillAfter to true , it means to keep the view at the last position when the animation end, (it's just visual , the real place of all your views will not change , so if you want to change the place of your view, see my edit – Houcine May 26 '11 at 00:17
  • Thanks for the update. Setting the padding for the scrollViewGroups did not update the place for the view, just the location of the elements inside fo the view. Is there any way to set the actual position of the views to reflect the current frame of the animation? – joe_coolish May 26 '11 at 00:41
  • apply the padding to the scrollViews ,and if it doesn't work , you can use SetMargins , see my edit again – Houcine May 26 '11 at 08:25