一、固定横竖屏

在AndroidManifest.xml的Activity配置中加入 android:screenOrientation=”landscape”属性(landscape是横向,portrait是纵向)。比如

  <activity android:name=".ContactsManagerActivity"                  android:label="@string/app_name"                  android:screenOrientation="portrait">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category    android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>

二、一般横竖屏切换时,activity要重启,为了避免重启,可以在activity中属性中假如:

android:configChanges=”orientation“,然后在activity中复写onConfigurationChanged()方法,例如

public void onConfigurationChanged(Configuration newConfig) {        // TODO Auto-generated method stub        if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) {            setContentView(R.layout.imageswitch);            //横屏        } else {            setContentView(R.layout.editcontact);//竖屏        }                super.onConfigurationChanged(newConfig);    }

这样就可以实现不重启activity,实现横竖屏切换了。


更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Fedora镜像
  3. python list.sort()根据多个关键字排序的方法实现
  4. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  5. Android中Bitmap.createBitmap重载方总结 和 Android实现位图剪
  6. Android中解决手机屏幕横竖屏切换问题
  7. Android横屏竖屏切换的问题
  8. android移动数据上网的开关的实现
  9. android:name属性加不加“.”

随机推荐

  1. Android(安卓)在 TextView 中设置超链接
  2. android开发之修改ListView默认滑动条样
  3. android系统内存管理知识(一)
  4. Mobile Atlas Creator 使用教學
  5. Android实现从网络获取图片显示并保存到S
  6. Android创建一个Activity的方法分析
  7. Android生成keystore方法
  8. MPAndroidChart项目实战(四)——柱状图实现
  9. IPCThreadState 详解
  10. Android实现卡拉OK字幕效果方法