开发者

Do screen dimensions matter when programming for Android tablet?

开发者 https://www.devze.com 2023-03-15 13:07 出处:网络
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 fo

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?


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.

<supports-screens android:smallScreens="true" 
                  android:normalScreens="true" 
                  android:largeScreens="true"
                  android:xlargeScreens="true"
                  android:anyDensity="true" />

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:

<manifest>
  <uses-sdk android:targetSdkVersion="11" />
</manifest>

Note that the target sdk can also be 12. Here's a link to the android version and sdk number.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消