我认为你的意思是这样做:
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);
注意:您可以使用DiplayMetrics类获取屏幕尺寸,
如果要将像素转换为 dp ,请参阅this
编辑:在动画结束后更改视图的位置
要做到这一点,你应该在你的动画上添加一个监听器,
animateGroups.addAnimationListener(AnimationListener);
并像这样覆盖方法:
@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);
}