Android显示活动水平(横向)失败

时间:2016-11-30 02:38:45

标签: android android-layout layout

我在水平方向上有一个关于Android显示活动的问题,这是我在AndroidMainfest.xml中的代码:

 <activity
        android:name="com.runmaf.paodong.activity_new.ResultChartDataActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="landscape">
 </activity>

并且在大多数情况下,活动在水平方向上显示: enter image description here

但有时活动会在垂直方向显示,如下所示: enter image description here

我还尝试将此处的代码添加到Activity onCreate方法中,但它会以垂直方向显示: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

我也关闭了手机的Automatic rotation function! 我不知道它发生了什么?需要你的帮助!

1 个答案:

答案 0 :(得分:0)

获得一般性答案(因为您提供的代码较少)

您可以在android:screenOrientation标记

中设置以下任意内容activity
android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]

并指定活动在设备上的显示方向。 但是

注意: 如果活动在多窗口模式中运行,系统将忽略此属性。 https://developer.android.com/guide/topics/ui/multi-window.html

如果不是你在挖掘代码中的情况,那么看看旋转属性的位置在哪里使用 例如:view.setRotaion(90);

请勿将orientation应用于应用元素,而应将该属性应用于activity元素,并且还必须设置configChanges,如下所示

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

注意android:configChanges“configChanges表示配置更改由活动本身处理。没有它,如果方向更改,活动将重新启动” “

如果您已指定方向为“纵向”,它将如何更改?如果您启动另一项改变方向的活动,则会更改,然后退出新活动,返回您的活动。例如,Samsung Galaxy S3上的默认图像捕获意图在某些方向上执行

引用此https://stackoverflow.com/a/4885663/5188159

相关问题