设为首页 加入收藏

TOP

Android中横屏切换的布局
2014-11-24 03:14:23 来源: 作者: 【 】 浏览:1
Tags:Android 切换 布局

切换这种效果多用在音视频播放器里面:


竖屏时这样显示:


Android中横屏切换的布局


横屏时这样显示:


Android中横屏切换的布局


activity代码:


package com.tmacsky;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
public class RotateSampleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lan);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
//启动时默认是竖屏
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.portrait);
}
//切换就是横屏
else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.lan);
}
}
}


layout文件直接在编辑器里拖4个button就可以了,水平布局lan和垂直布局portrait 2个layout文件


主要的是此时要在manifest.xml文件中添加权限:


< xml version="1.0" encoding="utf-8" >
package="com.tmacsky"
android:versionCode="1"
android:versionName="1.0" >

//给一个旋转后的权限


android:configChanges="orientation|locale"
android:label="@string/app_name" >







相关阅读:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇设置AndroidManifest.xml文件中An.. 下一篇Android中的自定义主题和样式

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)
·Python超详细一条龙 (2025-12-24 18:49:42)
·【超详细】JDK 下载 (2025-12-24 18:19:32)
·Java_百度百科 (2025-12-24 18:19:29)