横竖屏切换和contentView的三种显示方式
2016-03-22 08:49
531 查看
较常用,记下来方便查询
android:configChanges="orientation|keyboardHidden|screenSize"//加了之后横竖屏切换不重新创建Activity。
android:screenOrientation="landscape"//只横屏
android:screenOrientation="portrait"//只竖屏
//点击转换屏幕方向。
public void switchOrientation(View v) {
//1. 得到当前方向
int orientation = getResources().getConfiguration().orientation;
//2. 设置新的方向
if(orientation==Configuration.ORIENTATION_PORTRAIT) {
//变为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
显示contentView的三种方式
1.setContentView(R.layout.activity_main)
2.View view = View.inflate(this, R.layout.activity_main, null);
setContentView(view);
3.MyTextView tv = new MyTextView(this);
setContentView(tv);
android:configChanges="orientation|keyboardHidden|screenSize"//加了之后横竖屏切换不重新创建Activity。
android:screenOrientation="landscape"//只横屏
android:screenOrientation="portrait"//只竖屏
//点击转换屏幕方向。
public void switchOrientation(View v) {
//1. 得到当前方向
int orientation = getResources().getConfiguration().orientation;
//2. 设置新的方向
if(orientation==Configuration.ORIENTATION_PORTRAIT) {
//变为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
显示contentView的三种方式
1.setContentView(R.layout.activity_main)
2.View view = View.inflate(this, R.layout.activity_main, null);
setContentView(view);
3.MyTextView tv = new MyTextView(this);
setContentView(tv);
相关文章推荐
- Android实现表情 抓取新浪表情
- 详解Android解析Xml的三种方式——DOM、SAX以及XMLpull
- android开发环境遇到adt无法启动的问题分析及解决方法
- Android开发 旋转屏幕导致Activity重建解决方法
- Android开发技巧之在a标签或TextView控件中单击链接弹出Activity(自定义动作)
- Android开发技巧之ViewStub控件惰性装载
- Android开发常用经典代码段集锦
- 分享10个很棒的学习Android开发的网站
- android开发之横向滚动/竖向滚动的ListView(固定列头)
- Android开发技巧之我的菜单我做主(自定义菜单)
- Windows下使用Apache Cordova开发ANDROID之HelloWorld
- 根据根据图片的url怎么取得图片ImageView对象
- [转] ADB server didn't ACK
- android开发的相关链接
- Android数据存储之SharedPreferences 共享首选项/偏好设置
- 基于NDK的Android防破解
- 麦子学院android开发笔记:Android更换RatingBar图片
- android开发入门知识之AIDL详解
- AutoCompleteTextView组件的功能和用法