简体   繁体   English

如何处理屏幕方向?

[英]how to handle screen orientation?

In my program I set my layout orientation as vertical but if I am rotating my phone as horizontally than the screen is not appearing properly because the size of horizontal screen is less as compare to vertical so on keeping it on landscape mode the bottom part is not showing ,so how to fix all these problems?? 在我的程序中,我将布局方向设置为垂直,但是如果我将手机水平旋转,则屏幕无法正常显示,因为水平屏幕的尺寸小于垂直屏幕,因此在横向模式下底部不会显示,那么如何解决所有这些问题?

Please tell me that i want that on keeping it horizontal the screen will appear like as on vertical in the center of screen,please help me?? 请告诉我,我希望将其保持水平时,屏幕的显示效果将与屏幕中心的垂直方向一样,请帮助我?

一个非常常见且简单的解决方案是在/ res下创建一个新的layout-land文件夹,然后将原始xml复制到该新文件夹中,并使用android:orientation="horizontal"android:orientation="vertical"等XML进行调整

You can modify the manifest file (AndroidManifest.xml) and force the activity to have ONLY portrait mode, like so: 您可以修改清单文件(AndroidManifest.xml)并强制活动仅具有纵向模式,如下所示:

Please refer to the below thread: Android - disable landscape mode? 请参考以下主题: Android-禁用横向模式?

If you don't want to block orientation then try it: 如果您不想阻止方向,请尝试:

You can use separate xml for portrait and landscape mode. 您可以将单独的xml用于纵向和横向模式。

  1. you have to create separate folders layout-land, layout-port 您必须创建单独的文件夹layout-land,layout-port

  2. save the layout xml in it. 将布局xml保存在其中。

  3. Both layout xml should have the same name. 两个布局xml应该具有相同的名称。

Note: Keep the component id's same in both xml. 注意:两个xml中的组件ID均相同。 just make arrangements 只是安排

If you want to block orientation: 如果要阻止方向:

In your manifest 在你的清单上

<activity android:name="YOUR_ACTIVITY"
          android:screenOrientation="portrait" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM