简体   繁体   中英

Images for Different Screen sizes.?

I read the article http://developer.android.com/guide/practices/screens_support.html

I'm not quite clear on this: do I have to make different XML layouts to support different screen sizes?

Maybe there is a simple example that explains this in a way that is easier to understand?

No, the whole point of density is that one layout should work on all phones and devices. There's a good example of how to lay out buttons in a layout here .

Note on that link how one of the views has android:layout_marginTop="94dp" As long as you use dp, your layout should be fine for all devices.

Another way to put it: you don't have to worry about screen sizes as long as: a) You always measure distance in dp, not pixels b) You always measure font size in sp, not pixels c) For each image, you put different sizes of the image in the different resource folders (hdpi, xdhpi, etc)

If you follow those rules, one layout should look very similar on all sizes of screens.

No, you do not have to provide a layout for every size screen. You only have to have one layout for a screen. But by leveraging he resource system, you can provide alternate versions of your layout where it is appropriate. For example, maybe you want one layout for phones and a second layout for tablets.

Maybe not layout xmls but dimen xmls that should be repeated.

Sometimes,use dp can be help if you do not have to accurate to little pixels.

I'm not quite clear on this: do I have to make different XML layouts to support different screen sizes?

No. Make relative statements, such as android:layout_width="match_parent" . Use 9-patches to define stretchable images. File density and screen size dependent resources in the appropriate directory drawable, such as drawable-xhdpi . This will mean supplying the same image resource multiple times at different resolutions. ldpi is 33.33% of xhdpi , mpdi is 50%, and hdpi is 75%. xhpi is comparable to iPhone Retina: If someone gives you iOS Retina image assets, you can scale each of these down accordingly for Android.

A good occasion where you will have to make different XML layouts is if you're trying to remain backwards compatible. For example, android:layout_marginStart is only available from API 17 when Google started worrying about right-to-left text. This will fail silently on older devices, where instead you have to provide the same layout in layout-v10 say with android:layout_marginStart replaced by android:layout_marginLeft .

Last, think of your Android user interface as being a webpage. The only safe assumption you can make is that you have to fill space, don't presume how much space you have to fill.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM