开发者

Android layout animation question

I'm trying 开发者_如何学JAVAto 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!


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜