joe*_*ish 1 animation android android-layout
我正在尝试动画转换,但它没有给我正确的结果
我的布局看起来像这样:
Root
Groups
SubGroups
Root的方向设置为水平和两者Groups,SubGroups并且宽度和高度设置为父填充.
我想要的是动画Groups转换到屏幕的左边,这样只有~40 dp仍在显示,并且SubGroups向左翻译Groups,因此只Groups显示了一小部分,90%SubGroups是可见的.
这可能吗?谢谢你的帮助!
我认为你的意思是这样做:
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);
Run Code Online (Sandbox Code Playgroud)
注意:您可以使用DiplayMetrics类获取屏幕尺寸,如果要将像素转换为dp,请参阅此
编辑:在动画结束后更改视图的位置 来执行此操作,您应该添加一个监听器在您的动画上,
animateGroups.addAnimationListener(AnimationListener);
Run Code Online (Sandbox Code Playgroud)
并覆盖这样的方法:
@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);
}
Run Code Online (Sandbox Code Playgroud)