Android Api Demos登顶之路(十九)Rotation Animation
2015-08-05 05:59
543 查看
这个Demo演示了手机屏幕旋转时的动画效果,基本思路就是通过设置Window的属性,实现屏幕旋转时的动画效果, 但要求必须是Api18以上。
在这个小Demo上还出了一点小状况,程序运行时一直看不到效果,开始怀疑是不是自己对rotationAnimation 理解错了?查了一天的资料也没找到问题所在(不过还是有所收获的,呵呵),一天都比较郁闷。
后来才注意到, 当我旋转模拟器的屏幕时,屏幕的状态居然没有调整,于是在oncreate()方法里加了一了syso语句来监听 果然当屏幕旋转时居然没有重新调用oncreate()方法。
我用的是Api19的模拟器。不知道是模拟器有bug还是什么 原因,有知道的大神请帮忙解答下。不知道大家是否也遇到过这种情况。
后来换了一个Api18的模拟器,问题解决,运行正常。
布局文件activity .xml
MainActivity
在这个小Demo上还出了一点小状况,程序运行时一直看不到效果,开始怀疑是不是自己对rotationAnimation 理解错了?查了一天的资料也没找到问题所在(不过还是有所收获的,呵呵),一天都比较郁闷。
后来才注意到, 当我旋转模拟器的屏幕时,屏幕的状态居然没有调整,于是在oncreate()方法里加了一了syso语句来监听 果然当屏幕旋转时居然没有重新调用oncreate()方法。
我用的是Api19的模拟器。不知道是模拟器有bug还是什么 原因,有知道的大神请帮忙解答下。不知道大家是否也遇到过这种情况。
后来换了一个Api18的模拟器,问题解决,运行正常。
布局文件activity .xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="5dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/info" android:textAppearance="?android:attr/textAppearanceMedium" /> <CheckBox android:id="@+id/cb_fullScren" android:layout_marginTop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FULLSCREEN" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Rotation Animation:" android:layout_marginTop="10dp" android:textAppearance="?android:attr/textAppearanceMedium" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:checkedButton="@+id/rb_rotate" > <RadioButton android:id="@+id/rb_rotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ROTATE"/> <RadioButton android:id="@+id/rb_crossfade" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="XFADE" /> <RadioButton android:id="@+id/rb_jumpcut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="JUMPCUT" /> </RadioGroup> </LinearLayout>
MainActivity
public class MainActivity extends Activity { private int mRotationAnimation=LayoutParams.ROTATION_ANIMATION_ROTATE; private RadioGroup mRadioGroup; private CheckBox cb_fullScreen; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //设置默认的旋转动画 setRotationAnimation(mRotationAnimation); setContentView(R.layout.activity_main); mRadioGroup=(RadioGroup) findViewById(R.id.radioGroup); cb_fullScreen=(CheckBox) findViewById(R.id.cb_fullScren); cb_fullScreen.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { setFullScreen(isChecked); } }); //注意这里要使用全名RadioGroup.OnCheckedChangeListener() mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.rb_rotate: mRotationAnimation=WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE; break; case R.id.rb_crossfade: mRotationAnimation=WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE; break; case R.id.rb_jumpcut: mRotationAnimation=WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT; break; } setRotationAnimation(mRotationAnimation); } }); } /** * 设置窗体是否全屏显示 * @param on */ protected void setFullScreen(boolean on) { Window win=getWindow(); WindowManager.LayoutParams params=win.getAttributes(); if(on){ params.flags |=WindowManager.LayoutParams.FLAG_FULLSCREEN; }else{ params.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; } win.setAttributes(params); } /** * 设置旋转屏幕时的动画效果 * @param rotationAnimation:系统定义的动画常量 */ private void setRotationAnimation(int rotationAnimation) { Window win=getWindow(); WindowManager.LayoutParams params=win.getAttributes(); params.rotationAnimation=mRotationAnimation; win.setAttributes(params); } }
相关文章推荐
- android Toast文字加大
- 【Android开源项目分析】自定义圆形头像CircleImageView的使用和源码分析
- Android QQ空间说说回复功能简介
- [Android基础]Activity的生命周期
- Android:自定义dialog
- Android开源:数据库ORM框架GreenDao学习心得及使用总结
- Android-ViewPagerIndicator框架使用——TitlePageIndicator
- Android4.0 G-Sensor工作流程
- Android-Gsensor屏幕旋转
- Android.mk文件分析
- 为什么在AndroidManifest.xml中Activity的theme用不了Theme.Light.NoTitleBar?
- Android复习笔记(12) -handler的使用
- Android-升级数据库的最佳写法
- Android 提升ListView的运行效率
- Fedora22和Ubuntu 配置android SDK的32位库
- 【扣丁学堂】2015版Android系列视频拍摄感悟
- android常用布局
- android四大组件
- android常见布局补充
- android 之 SurfaceView使用(桌面弹球)