سؤال

I understand there is plenty of documentation about designing for multiple screen support in Android. and I have read the Android guide here as well as a number of similar questions such as this

However I'm still a little confused as to how I should implement it for my application. I plan to target the following device configurations

enter image description here

Am I correct in thinking I will need to structure the project layouts as follows:

  • Medium density Normal screens HVGA 320x480 (160dpi):

    res/layout-mdpi (320 x 480 )
    res/layout-land-mdpi (480 x 320 )
    
  • High density Normal screens WVGA800 480x800 (x854) (240 dpi)

    res/layout-hdpi (480 x 800)
    res/layout-land-hdpi (800 x 480)
    

But what about the Medium density, large screen devices?

I plan to use sets of both high and medium density drawables too. My primary concern at this early stage is using suitable background images for each layout. For example, to support both the 480x800 and 480x854 sizes, I plan to simply use an ImageView as the background such as:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/bg"
    android:scaleType="center"/>

The 'bg' drawable will always be 480x854 and by using:

android:scaleType="center"

I'm hoping this will take care of those two screen sizes. Whereby the image keeps its original appearance but is centred on the 480x800 screens. I will lose some pixels off the image but as long as the image isn't scaled then that suits my needs.

I plan to have a set of 320x480 assets for the normal screens.

I'm just hoping I'm following the correct procedure here so I appreciate any info/tips from you guys. Thanks in advance

هل كانت مفيدة؟

المحلول

In my experience you don't really need to customize your layout for the small/medium/large/etc screens, as long as you have your drawables for the different densities. Like the documentation says, Android will attempt to render your layout properly on different screen sizes.

By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes.

The 'other cases' applies only if you really want to change your layout on larger screens.

Using android:scaleType="center" works for me, but it will, like you said, leave empty space around your layout on larger screens if it should fit on smaller screens as well. If you have a fully customized view with 'widgets' that should be placed exactly right, and you don't want to be programmatically determining the scaling and applying the same scaling to your widgets, this is definitely the way to go.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top