레이블이 Screen configuration인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Screen configuration인 게시물을 표시합니다. 모든 게시물 표시

2014년 9월 9일 화요일

Supporting different layouts & bitmaps

Create different layouts for each screen size you want to support to optimize user experience. Each layout file should be saved into the appropriate resource directory, named with a -<screen_size> suffix.

e.g.
My Project
       - res/
             - layout/                     ==> default portrait
                         main.xml
             - layout-land              ==> landscape
                         main.xml
             - layout-large/            ==> large portrait
                         main.xml
             - layout-large-land     ==> large landscape
                         main.xml

The file names must be exactly the same, but their contents are different in order to provide an optimized UI for the corresponding screen size.


Providing bitmap resources that are properly scaled to each of generalized densities: low, medium, high, etc. will help to achieve good graphical quality and performance on all screen densities.

To generate images, start with raw resources in vector format and generate the images for each density using the following size scales:

  • xxxhdpi: 4.0
  • xxhdpi: 3.0
  • xhdpi: 2.0
  • hdpi: 1.5
  • mdpi: 1.0 (baseline)
  • ldpi: 0.75
If we generate a 200x200 image for xhdpi, we should generate the same resources in 150x150 for hdpi, 100x100 for mdpi, 300x300 for xxhdpi and then place them in the appropriate drawable resource directory:

e.g.

My Project
       - res/
             - drawable-xxhdpi/                  
                         example.png
             - drawable-xhdpi            
                         example.png
             - drawable-hdpi/
                         example.png
             - drawable-mdpi
                         example.png



Controlling App's Availability to Devices

Android supports a variety of features, some of them are hardware-based, some are software-based, and some are dependent on platform version. So app developer may need to control app's availability to devices based on app's required features.

We can restrict app's availability to devices through Google Play Store based on the following device characteristics:

  1. Device features
  2. Platform version
  3. Screen configuration

Device features:
Android defines feature IDs for any hardware or software feature that may not be available on all devices. So we can prevent users from installing app when their devices don't provide a given feature by declaring it with a <uses-feature> element in app's manifest file.

e.g. declaring the compass sensor as required
<uses-feature android:name="android.hardware.sensor.compass"
                       android:required="true" />

Google Play Store compares the features app requires to the features available on user's device to determine whether the app is compatible with each device. If the device does not provide all the features, the user cannot install the app.

In case device features are not required for running app's primary functionality, then set the required attribute to "false"  and check for device feature at runtime.
PackageManager pm = getPackageManager();
if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
  // No compass available on this device, turn off the compass feature
  disableCompassFeature();
}


Platform version:
Different devices may run different versions of Android, which means new APIs of newer Android version may not be available on older versions of Android.

API level allows to declare the minimum version with which your app is compatible using <uses-sdk> element in app's manifest file.

e.g.
<uses-sdk android:minSdkVersion="14"
                 android:targetSdkVersion="19" />

minSdkVersion: declares the minimum version with which app is compatible
targetSdkVersion: declares the highest version on which app has been optimized

We can check the API level at runtime and gracefully degrade the corresponding features when the API level is too low.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
  // running on something older than API 11, so disable features
  disableSomeFeature();
}

Screen configuration:
Android runs on devices of various sizes from smart phones to TVs. In order to categorize devices by screen type, Android defines two characteristics for each devices: screen size (physical size) and screen density (DPI)

  • generalized sizes: small, normal, large and xlarge
  • generalized densities: mdpi (medium), hdpi, xhdpi (extra high), xxhdpi (extra-extra high)
By default most apps are compatible with all screen sizes and densities because the system makes all the adjustments to UI layout and image resources as necessary for each screen. However we can optimize the user experience for each screen configuration by adding specialized layouts for different screen sizes and optimized bitmap images for common screen densities.

For more information in detail, check the following developers site: