您的位置:首页 > 移动开发 > Android开发

自定义可以旋转的控件

2017-10-03 21:41 106 查看
public class AnimationUtil  {
public static void rotateOutAnim(RelativeLayout relativeLayout,long delay){
int childCount=relativeLayout.getChildCount();
for (int i=0;i<childCount;i++){
relativeLayout.getChildAt(i).setEnabled(false);
}
RotateAnimation ra =new RotateAnimation(0f,-180f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,1.0f);
ra.setDuration(500);
ra.setFillAfter(true);
ra.setStartOffset(delay);
relativeLayout.startAnimation(ra);
}
public static void rotateInAnim(RelativeLayout relativeLayout){
int childCount=relativeLayout.getChildCount();
for (int i=0;i<childCount;i++){
relativeLayout.getChildAt(i).setEnabled(true);
}
RotateAnimation ra =new RotateAnimation(-180f,0f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,1.0f);
ra.setDuration(500);
ra.setFillAfter(true);
relativeLayout.startAnimation(ra);
}
}
这是用于旋转控件的工具类,首先配置新增一个旋转动画类,传入layout后将layout进行旋转。
需要进行旋转时就找出layout的实例,将其作为参数传入工具类的旋转方法里就行
level2=(RelativeLayout)findViewById(R.id.level2);
AnimationUtil.rotateOutAnim(level2,0);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android
相关文章推荐