2011年9月27日 星期二

[AndroidDev] Android Developers Blog: Preparing for Handsets



* Above code support  your app’s screen-size only for tablet in two different ways:
  1. It declares that the app does not support the screen size buckets “small”, “normal”, and “large”, which are traditionally not tablets
  2. It declares that the app requires a screen size with a minimum usable area that is at least 600dp wide

requiresSmallestWidthDp attribute is the new API supported from Android 3.2.

* The safest thing to do is develop your app against the platform that matches the API level you’ve set for minSdkVersion.

* For more information about why the “smallest width” screen size is important for supporting different screen sizes, read New Tools for Managing Screen Sizes (really; it’s got lots of things you need to know).

* Here are two guidelines to help make your Honeycomb tablet app work well on handsets:
  1. Build your design around Fragments that you can reuse in different combinations, in single-pane layouts on handsets and multi-pane layouts on tablets
  2. Be conservative with your Action Bar design so the system can adjust its layout based on the screen size

* Creating single-pane and multi-pane layouts
  • Single activity: Swapping the fragments within the activity when necessary.
    • Dynamically add each fragment to the activity at runtime---rather than declare the fragments in your activity’s layout file — because you cannot remove a fragment from an activity if it’s been declared in the XML layout.
  • Use separate activities to host each fragment on a handset.
    • When you need to switch fragments (such as when the user selects an item), start another activity that hosts the other fragment.


* Specifically, you should follow two general guidelines:
  • Do not manipulate one fragment directly from another.
    • To avoid directly calling one fragment from another, declare a callback interface in each fragment class that it can use to deliver events to its host activity, which implements the callback interface. When the activity receives a callback due to an event (such as the user selecting a list item), it acts appropriately based on the current fragment configuration.
  • Keep all code that concerns content in a fragment inside that fragment, rather than putting it in the host activity’s code.


* Here are some important tips:
  • When setting a menu item to be an action item, avoid using the “always” value. Use “ifRoom” for action items you’d like to add to the action bar. 
    • Now, you might need “always” when an action view does not have an alternative action for the overflow menu or when a menu item added by a fragment is low in the menu order and it must jump into the action bar at all times. But you should not use “always” more than once or twice.
  • When possible, provide icons for all action items and declare showAsAction="ifRoom|withText"
    • This way, if there’s not enough room for the text, but there is enough for the icon, then just the icon may be used.
  • Avoid using custom navigation modes in the action bar. Use the built-in tab and drop-down navigation modes.
    • They’re designed to be flexible and adapt to different screen sizes. 
    • For example, when the width is too narrow for both tabs and other action items, the tabs appear below the action bar. If your app requires a custom navigation mode in the action bar, thoroughly test it on smaller screens when Ice Cream Sandwich becomes available and make any adjustments necessary for a narrow action bar.


* Some other tips
  • When working with a ListView, consider how you might provide more or less information in each list item based on the available space. That is, you can create alternative layouts to be used by the items in your list adapter such that a large screen might display more detail for each item.
  • Create alternative resource files for values such as integers, dimensions, and even booleans. Using size qualifiers for these resources, you can easily apply different layout sizes, font sizes, or enable/disable features based on the current screen size.



* Reference
- Android Developers Blog: Preparing for Handsets

沒有留言:

張貼留言