为 Android 平板电脑编程时,屏幕尺寸重要吗?
这是我第一次为 PC 以外的任何东西编程。我认为屏幕尺寸和方向之类的东西在平板电脑上很重要,但在一些基本示例代码中我发现没有任何与此相关的内容。旋转和调整大小会自动发生吗?如果没有,如何使应用程序全屏显示?
It's my first time programming for anything that isn't a PC. I would assume that things like screen dimensions and orientation would matter on a tablet, but in the bits of basic sample code I've found there hasn't been anything about this. Does rotating and resizing automatically happen? If not, how do I make the app full-screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速回答:是的,android 会自动将您的布局适合设备屏幕。您可以根据设备的尺寸和方向采用特定的布局。 Android 管理使用哪些以及如何处理旋转。
当平板电脑旋转时,会触发配置更改事件。如果您的应用程序没有声明它将亲自处理此事件,那么 Android 框架会为您处理它。当框架处理它时,您的应用程序将被终止并重新启动。这允许应用程序加载不同的布局(如果您为横向/纵向指定了不同的布局)。其他配置更改(例如区域设置和许多其他配置)也会发生同样的情况。
有两种方法可以使应用程序全屏显示。 第一个只是说明应用程序支持特定的 dpi。 Manifest 中的以下代码支持所有 dpi。
第二种方法是声明应用程序已经过测试并且可以通过 targetSdk 支持更大的屏幕尺寸。然而,这会删除可能存在的任何兼容性功能。例如,我有一个应用程序在用户界面线程上进行了一些大量处理,当我添加 targetSdkVersion 代码以使我的应用程序屏幕更大时,该应用程序不再工作。这是因为 targetSdkVersion 不仅使屏幕更大,而且还删除了允许前端线程执行长进程的兼容性代码。这就是你的警告。代码如下:
请注意,目标 sdk 也可以是 12。这是一个链接 Android 版本和 sdk 编号。
Quick answer: yes android automatically fits your layouts to the devices screen. You can have specific layouts depending on the size and orientation of the devices. Android manages which ones to use and how to handle rotations.
When the tablet is rotated, a configuration changed event is fired. If your application doesn't state that it will personally handle this event then the android framework handles it for you. When the framework handles it, your application is killed and restarted. This allows the application to load a different layout (if you specified a different layout for landscape/portrait). The same thing happens for other configurations changes such as locale and many others.
There are two methods to make an application full screen. The first simply states the application supports a specific dpi. The following code in the Manifest supports all dpis.
The second method is to state that the application has been tested for and can support larger screen sizes via the targetSdk. This however, removes any compatibility features that may have existed. For example, I had an application that did some massive processing on the user interface thread, when I added the targetSdkVersion code to make my applications screen larger, the application no longer worked. This was because the targetSdkVersion not only made the screen bigger, it removed compatibility code that allowed the front end thread to do long processes. So that is your warning. Here's the code:
Note that the target sdk can also be 12. Here's a link to the android version and sdk number.
您可以通过在 xml 或布局设计器中设置主题来使 Activity 全屏显示,例如 Theme.Black.NoTitleBar.Fullscreen 将为您提供全屏 Activity。
如果您旋转设备,那么它将使用相同的布局,除非您定义了替代布局。我通常从制作纵向布局开始,然后您可以简单地制作相同布局的横向版本,但对于平板电脑,您可能想要开始横向,因为这是主要方向。
看看这个视频,它涵盖了布局编辑器的这个功能和其他一些方便的功能:
http://youtu.be/Oq05KqjXTvs
希望这可以帮助您入门!
You can make an activity full screen by setting the theme in the xml or layout designer, for example Theme.Black.NoTitleBar.Fullscreen will give you an activity that is fullscreen.
If you rotate a device then it will use the same layout unless you have defined an alternative layout. I usually start by making a portrait layout then you can simply make a landscape version of the same layout, but for tablet you'll probably want to start landscape since that is the main orientation.
Take a look at this video it covers this and some other handy features of the layout editor:
http://youtu.be/Oq05KqjXTvs
Hope this helps get you started!