当前位置:首页 » 安卓系统 » android代码竖屏

android代码竖屏

发布时间: 2022-09-28 20:04:59

⑴ android怎么设置横竖屏切换

方法一:

1、首先在android手机打开“设置”这个选项的,点击“显示”这个功能;

⑵ android系统强制横竖屏实现

横屏:
按照下面代码示例修改Activity的onResume方法
@Override
protected void onResume() {
/**
* 设置为横屏
*/
if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}

或者在配置文件中对Activity节点添加android:screenOrientation属性(landscape是横向,portrait是纵向)
android:launchMode="singleTask" android:screenOrientation="portrait">

竖屏:
要设置成竖屏将上面代码中,属性设置成 SCREEN_ORIENTATION_PORTRAIT即可。

⑶ android如何禁止横竖屏切换

禁用横竖屏切换,有两种方式,第一种是在配置文件中配置,第二种是在java代码中设置。

第一种是在AndroidManifest.xml中,为activity节点配置android:screenOrientation属性,指定该activity为竖屏或横屏,我们将上面的这个activity的配置为竖屏,如下:

<activity
android:name="chengyujia.androidtest.OrientationActivity"
android:screenOrientation="portrait" />
再运行测试,此时无论手机屏幕方向如何,该activity始终是竖屏的。如果android:screenOrientation="landscape" 则始终是横屏。

下面来看第二种,

只要在onCreate方法中加一句

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
即可始终保持竖屏,如果要横屏,代码是

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

⑷ 怎么用Android代码锁定整个app竖屏

方法:用压缩软件打开apk文件,解压出根目录中的classes.dex文件 使用cmd ,dex2jar.bat classes.dex命令将classes.dex转换为jar 再用jd-gui打开该jar就可以查看源码了,如果apk安全性好的话,有些代码是看不到的。

⑸ 怎么用Android代码锁定整个app竖屏

清单注册文件:android:screenOrientation=""

<activity
android:name="..."
android:screenOrientation="...">

⑹ android如何在代码中判断横竖屏

Android中判断横竖屏是通过Configuration 这个类来判断的。

  1. Configuration.ORIENTATION_LANDSCAPE 表示横屏。

  2. Configuration.ORIENTATION_PORTRAIT表示竖屏。


以下是完整代码:

public boolean isScreenChange() {

Configuration mConfiguration = context.getResources().getConfiguration(); //获取设置的配置信息
int ori = mConfiguration.orientation ; //获取屏幕方向
if(ori == Configuration.ORIENTATION_LANDSCAPE){
//横屏
return true;
}else if(ori == Configuration.ORIENTATION_PORTRAIT){
//竖屏
return false;
}
return false;
}


避免在转屏时重启Activity

android中每次屏幕方向切换时都会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activity再次 Create的时候载入配置,那样,进行中的游戏就不会自动重启了!
要避免在转屏时重启Activity,可以通过在AndroidManifest.xml文件中重新定义方向(给每个Activity加上android:configChanges=”keyboardHidden|orientation”属性)。
在需要控制屏幕显示方向的Activity中重写onConfigurationChanged(Configuration newConfig)方法,这样在转屏时就不会重启Activity了。

⑺ 如何设置android界面横屏显示

全屏

在Activity的onCreate方法中的setContentView(myview)调用之前添加下面代码

requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏

横屏

按照下面代码示例修改Activity的onResume方法

@Override
protected void onResume() {
/**
* 设置为横屏
*/
if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
super.onResume();
}

或者在配置文件中对Activity节点添加android:screenOrientation属性(landscape是横向,portrait是纵向)

android:launchMode="singleTask" android:screenOrientation="portrait">

要设置成竖屏设置成 SCREEN_ORIENTATION_PORTRAIT

// ----------------

常亮

view.setKeepScreenOn(true)

不加任何旋转屏幕的处理代码的时候,旋转屏幕将会导致系统把当前activity关闭,重新打开。
如果只是简单的界面调整,我们可以阻止此问题的发生,屏幕旋转而自己调整屏幕的元素重构。
首先我们需要修改AndroidManifest.xml文件:
<activity android:name=".Magazine">
</activity>
//修改为:
<activity android:name=".Magazine"
android:configChanges="orientation|keyboard">
</activity>
这样是让程序能够响应旋转屏幕的事件。
然后重写onConfigurationChanged方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.v(" == onConfigurationChanged");
processLayout();
}

//----------------------------

在我们用Android开发过程中,会碰到Activity在切换到后台或布局从横屏LANDSCAPE切换到PORTRAIT,会重新切换Activity会触发一次onCreate方法。

在Android开发中这种情况视可以避免的,我们可以在androidmanifest.xml中的activit元素加入这个属性 android:configChanges="orientation|keyboardHidden" 就能有效避免oncreat方法的重复加载,

androidmanifest.xml内容如下:红色字体为添加部分

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.demo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DemoGPS"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />

</application>
<uses-sdk android:minSdkVersion="7" />

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

</manifest>

同时在Activity的Java文件中重载onConfigurationChanged(Configuration newConfig)这个方法,这样就不会在布局切换或窗口切换时重载等方法。代码如下:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
//land
}
else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
//port
}
}

//------------------------------------------------------

关于Android中Activity的横竖屏切换问题可以通过AndroidManifest.xml文件中的Activity来配置:

android:screenOrientation=["unspecified" | "user" | "behind" |
"landscape" | "portrait" |
"sensor" | "nonsensor"]

screenOrientation 用来指定Activity的在设备上显示的方向,每个值代表如下含义:

"unspecified" 默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向.

"landscape" 横屏显示(宽比高要长)

"portrait" 竖屏显示(高比宽要长)

"user" 用户当前首选的方向

"behind" 和该Activity下面的那个Activity的方向一致(在Activity堆栈中的)

"sensor" 有物理的感应器来决定。如果用户旋转设备这屏幕会横竖屏切换。

"nosensor" 忽略物理感应器,这样就不会随着用户旋转设备而更改了 ( "unspecified"设置除外 )。

更多安卓例子请去360手机助手下载安卓学习手册,里面有横竖排例子,源码,例子随便看。

⑻ android开发横竖屏问题

Android横屏竖屏设置

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();

热点内容
三星怎么应用加密 发布:2024-05-05 17:13:18 浏览:151
cad字体在那个文件夹 发布:2024-05-05 17:08:20 浏览:329
什么时候用编译器 发布:2024-05-05 17:08:20 浏览:764
应急救援脚本 发布:2024-05-05 17:08:17 浏览:336
我的世界搭建无正版验证服务器 发布:2024-05-05 17:03:48 浏览:817
我的世界服务器地址宝可梦 发布:2024-05-05 17:00:16 浏览:254
dede企业源码 发布:2024-05-05 16:57:53 浏览:786
如何查看java版本 发布:2024-05-05 16:45:05 浏览:494
转子绕组电动机控制柜如何配置 发布:2024-05-05 16:45:04 浏览:917
搭建游戏要多大服务器 发布:2024-05-05 16:44:16 浏览:346