180 likes | 193 Views
Introduction to tablet optimization. Indy Android Developers - Oct 15, 2013. Overview. Why Optimize for Tablets? Using Fragments Using the Action Bar Available Resources. Why Optimize for tablets?.
E N D
Introduction totablet optimization • Indy Android Developers - Oct 15, 2013
Overview • Why Optimize for Tablets? • Using Fragments • Using the Action Bar • Available Resources
Why Optimize for tablets? • Most apps that are designed with flexible layouts will work perfectly fine on tablets by utilizing scaling. • The main reason to further optimize your Android app for tablets is to greater utilize the available space on bigger screens, and present a better user interface over the automatically scaled interface.
Using Fragments • With API 11 Android introduced a new set of framework APIs called Fragments • Fragments allow you to break up your UI elements into individual classes and then organize those fragments dynamically in an activity • Fragments are available in the Support Library for older Android versions
Using Fragments - Overview • Single-pane and Multi-pane Layouts • Multiple Fragments, One Activity • Multiple Fragments, Multiple Activities • Using Multiple Fragment Layouts • Guidelines for Fragments • Layout Selectors
Single-Pane and Multi-pane Layouts • There are two distinct ways to optimize your app using fragments for multiple screen sizes. • The first is Multiple Fragments, One Activity • The second is Multiple Fragments, Multiple Activities
Multiple Fragments, One Activity • You create one main activity for your app UI, and then switch fragments in and out of that activity based on the screen size. • Fragments must be created programmatically instead of through XML because any fragment created in XML cannot be removed from the layout. • The Action Bar must be updated when switching out Fragments in the activity • You have to manually manage the back stack using the FragmentManager
Multiple fragments, multiple activities • You create separate layouts for small screens and large screens. • On large screens, you put multiple fragments in your layouts • On smaller screens, you put single fragments in your layouts • Fragments can be defined in XML
Multiple fragments, multiple activities • You still use one main activity, but the correct layout is automatically determined by Android based on layout selectors. • When switching screens, you load a new activity instead of swapping out fragments • This is the suggested method in the Android Best Practices for Supporting Tablets and Handsets
using multiple fragment layouts • When using multiple layouts, you need to determine if the fragment is available before trying to reference it. • FragmentManager.findFragmentById(FRAGMENT_ID) • If the Fragment exists, interact with it • If the Fragment does not exist, start a new Activity that contains it
Guidelines for Fragments • Do not manipulate one fragment directly from another • Define callbacks in your fragments that the activity can implement to listen for events • Keep all code that concerns content in a fragment inside that fragment
Layout Selectors • Small screens would use the default selector: res/layouts/main.xml • Larger screens would use the larger selector: res/layouts-large/main.xml • API13 and above support more fine grained layout selectors
Using the action bar • The ActionBar will automatically resize when the screen size changes • If you are using a standard ActionBar and handling ActionBar buttons correctly, you can let Android handle your navigation changes for you on different screen sizes
Using the action bar - overview • Using the Overflow Menu • Using the Split Action Bar • Supporting Older Android Versions
using the overflow menu • When defining your ActionBar buttons, you have a setting called “showAsAction” • If you set this option to “ifRoom”, the button will only show up if there is enough room on the screen to show it • If you are using ActionBar button titles, you can also use “ifRoom|withText” to hide those titles when on a smaller screen • You can still use “always” for really important buttons, but you shouldn’t use more than two of these
using the split action bar • If you are using API14 or higher, you can enable the split ActionBar to handle overflow items • The split ActionBar shows up at the bottom of the screen on smaller devices • To enable, you set the “uiOptions” attribute to “splitActionBarWhenNarrow” to your <activity> or <application> elements in your manifest file • This option is ignored on older devices and should therefore be safe to use
supporting older android versions • The ActionBar was first introduced in API 11 which is Android 3.0 • To use the ActionBar in older versions of Android, you should use the Support Library • You can use third-party ActionBar implementations such as ActionBarSherlock to provide a easier fallback on older Android versions
available resources • http://developer.android.com/guide/practices/tablets-and-handsets.html - Supporting Tablets and Handsets • http://developer.android.com/guide/practices/screens_support.html - Supporting Multiple Screens • http://android-developers.blogspot.com/2012/11/designing-for-tablets-were-here-to-help.html - Designing for Tablets • http://developer.android.com/distribute/googleplay/quality/tablet.html - Tablet App Quality Checklist • http://developer.android.com/guide/topics/ui/actionbar.html - Action Bar