简体   繁体   中英

How to use different screen size specific values in android devices

I have an issue, in specifying the dimension values to the device, since the height of the device (Device 1) is small compared to other devices, one of the view looks chopped. I was asked to create a separate res/values folder to include resources (dimen.xml) for the small screen sizes.

I ran the "adb shell dumpsys window" command to get the screen size as below.

Device 1:

mCurConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw391dp w696dp h367dp 294dpi nrml long land finger12key/v/h-nav/h s.5}

Device 2:

mGlobalConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw492dp w787dp h492dp 260dpi lrg land finger -keyb/v/h -nav/h appBounds=Rect(0, 0 - 1280, 800) s.11}

Device 3:

 mCurConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw340dp w340dp h560dp 128dpi nrml long port finger qwerty/v/h dpad/v s.5}
  mHasPermanentDpad=false

Device 4:

  mCurConfiguration={1.0 ?mcc?mnc [en_US] ldltr sw600dp w1024dp h560dp 160dpi lrg long land finger qwerty/v/h dpad/v s.5}

Do I need to name my values folder as res/values-sw391dp? And will the dimen.xml declared inside this folder will be applicable to device 1, and will not be used by device 2, device 3 and device 4.

So yeah you would create the new layout in android studio.

When it asks you for a name, name it exactly the same as the layout that you are trying to copy but for different configuration.

Then add the qualifier, whatever you want as you see, height, width, diagonal etc etc.

And then it would create the new layout for you.

With screen sizes suppose you have 3 layouts: main_activity.xml, main_activity.xml(w320dp),main_activity(w600dp).

Then devices with width smaller than 320 will use main_activity.xml;

Devices with width between 320 and 600 will use main_activity.xml(w320dp);

And devices with width above 600 (pretty much tablets) will use main_activity.xml(w600dp)

And so yeah thats how you set up different layouts for different screen sizes

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