Best way for Multiple Screen Support - Android Studio

我只是一个虾纸丫 提交于 2019-12-08 04:40:49

问题


To support multiple screen size, what is the best way to do so ? in my manifest, i created the

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

also i created different layout sizes and dimens

layout-small
layout-normal
layout-large
layout-xlarge

I would have to individually edit which layouts to fit all the screens. But then some phone screen are able to detect the different screen size layout, but there's still some alignment difference. while for some phones, the layouts will go out of the screen.

Is this the correct way to do so ? or is there other alternate way for screen support ?

so i must individually change all the layouts ? is there a better way than changing the layouts one by one ? cause for my project, in total, i have more than 30 layouts. so if i create

layout-small
layout-normal
layout-large
layout-xlarge,

there will be more than 100 of different layouts to edit. Thanks.


回答1:


A set of six generalized densities:-

ldpi (low) ~120dpi mdpi (medium) ~160dpi hdpi (high) ~240dpi xhdpi (extra-high) ~320dpi xxhdpi (extra-extra-high) ~480dpi xxxhdpi (extra-extra-extra-high) ~640dpi

Screen Size:-

xlarge screens are at least 960dp x 720dp large screens are at least 640dp x 480dp normal screens are at least 470dp x 320dp small screens are at least 426dp x 320dp

Provide different layouts for different screen sizes:-

The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra-large screen should go in layout-xlarge/

For further reference use tis link:-

http://developer.android.com/guide/practices/screens_support.html




回答2:


If your layout remains the same on different screens/ orientations, I will suggest you place only one layout in the layout folder and use RelativeLayout or ConstraintLayout to dynamically adjust content on different screen sizes. Try not to hardcode the placement of UI components (in pixels) and stick with relative positioning.




回答3:


You can use Library that can handle all the dimension of your screen sizes

/**
 * For All Dimensions excepts textview and Edit text sizes
 */
implementation 'com.intuit.sdp:sdp-android:1.0.5'
/**
 * For TextView and Edit Texts Sizes.
 */
implementation 'com.intuit.ssp:ssp-android:1.0.6'


来源:https://stackoverflow.com/questions/34034498/best-way-for-multiple-screen-support-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!