getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置成全屏模式
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE););//强制为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
我做的东西里面还用到了去掉标题栏。
我也贴出来
requestWindowFeature(Window.FEATURE_NO_TITLE);
垂直居中:
android:layout_centerVertical="true"
水平居中:
android:layout_centerHorizontal="true"
1.hideStatusbarAndTitlebar()隐藏statusbar和titlebar.
private void hideStatusbarAndTitlebar() {
final Window win = getWindow();
// No Statusbar
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// No Titlebar
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
2.设置屏幕显示模式ScreenOrientation.
在activity里设置android:screenOrientation的值。
android:screenOrientation的属性有以下值:
unspecified(默认值,由系统判断状态自动切换),The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
landscape,横屏
portrait,竖屏
user(用户当前设置的orientation值),The user's current preferred orientation.
behind(下一个要显示的Activity的orientation值),The same orientation as the activity that's immediately beneath it in the activity stack.
sensor(传感器的方向),The orientation determined by a physical orientation sensor. The orientation of the display depends on how the user is holding the device; it changes when the user rotates the device.
nosensor(不使用传感器,这个效果差不多等于unspecified).An orientation determined without reference to a physical orientation sensor. The sensor is ignored, so the display will not rotate based on how the user moves the device. Except for this distinction, the system chooses the orientation using the same policy as for the "unspecified" setting.
3.水平/垂直居中的方法.
设置parent的android:gravity为"center"。
4.获得当前屏幕宽高的方法.
Display display = getWindowManager().getDefaultDisplay();
Config.screenWidth = display.getWidth();
Config.screenHeight = display.getHeight();
相关推荐
Android studio通过切换不同layout实现横竖屏适配
Android 简单例子:横屏 竖屏切换功能实例,当屏幕为横屏时,可将屏幕切换成竖屏状态,并检测屏幕是否切换成功。反之,当屏幕为竖屏时切换为横屏显示。
亲测,完美支持横屏改竖屏,不变形,识别速度还不错! 包含3.2源码包和修改方法。
android横竖屏
如果你发现你怎么样去弄都不能把手机的界面布局做好,甚至你连怎么做都不知道的话,赶紧下载这个看看!
android二维码扫描里面有竖屏和横屏的工程,竖屏的是简化版的只能扫描文本内带core2.0的核心包,横屏的是google源代码。
在Android中要让一个程序的界面始终保持一个方向,不随手机方向转动而变化的办法: 只要在AndroidManifest.xml里面配置一下就可以了。 在AndroidManifest.xml的activity(需要禁止转向的activity)配置中加入...
Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化 例如: 切换到横屏 onSaveInstanceState onPause onStop onDestroy onCreate onStart onRestoreInstanceState onResume
android二维码横屏竖屏都在压缩包中,经过测试,均可用。放心下载吧!
基于mtk平台,手机平台默认竖屏显示,根据此提取包可以要做成横屏模式。
根据大家需要,我把4.4kk电量BatteryMeterView图片分为横屏和竖屏,可以给大家解决自身的问题
Android自适应屏幕大小和layout布局(横屏竖屏)[定义].pdf
主要介绍了Android编程判断横屏、竖屏及设置横竖屏的方法,结合实例形式分析了Android针对横竖屏的判断、计算、设置等相关操作技巧,需要的朋友可以参考下
ANDROID自适应屏幕大小和LAYOUT布局横屏竖屏
主要介绍了Android屏幕旋转之横屏竖屏切换的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
让AndroidX86竖屏显示,默认情况下该版本Android是横屏显示,此文档可以帮你设置能竖屏显示
android 手机强制横竖屏 下载直接运行 !!!!!!!!
Android横竖屏切换,包含代码中横屏 180 旋转 ,竖屏180 旋转; //横屏正方向 if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_...
用Fragment实现的横竖屏不一样的布局,详情Android 一个例子来解读Fragment实现横竖屏不同的布局http://blog.csdn.net/xiaanming/article/details/9254749
android安卓app处理屏幕旋转事件,竖屏变横屏,横屏变竖屏