0

I am supporting split screen in my application. I want the imageview size to be set from dimens.xml when the width changes. If the screen width = 275 , the app is taking textview size from dimens.xml . How can I make app to take the imageview size from different dimens.xml if the screen width is 275dp, 320dp because the screen width varies when user changes the screen size in split screen ?

Vinay
  • 1,284
  • 14
  • 24
  • 1
    There are multiple answer to this: https://stackoverflow.com/questions/32860815/how-to-define-dimens-xml-for-every-different-screen-size-in-android or the official docs: https://developer.android.com/training/multiscreen/screensizes – MatPag Dec 16 '19 at 12:27
  • use ssp and sdp dependency – Atif AbbAsi Dec 16 '19 at 12:46

1 Answers1

0

You should create new values resources directory, like values-w275dp and values-w320dp. This will be applied for screens with exact width. It's better to use Smallest Screen Width

  • Right click on res -> New -> Android Resource Directory
  • Set Resource type to values
  • Select Available qualifiers - Screeh Width
  • Click >>
  • Set desirable screen width

Vitalii Malyi
  • 874
  • 6
  • 13
  • In reality he should be using `smallest screen width` to be safer – MatPag Dec 16 '19 at 12:39
  • @MatPag yes, it will be definitely better – Vitalii Malyi Dec 16 '19 at 12:40
  • @MatPag I did as you said, creating the dimens.xml (sw-275) but the app takes dimensions from . dimens.xml (sw-275) even in normal mode i.e not split-mode instead of taking from dimens.xml – Vinay Dec 16 '19 at 13:08
  • @Vinay the folders should be in this form: `values-swXdp` where X is DP value, and you can add a custom `dimens.xml` in each of them – MatPag Dec 16 '19 at 13:28
  • @MatPag i did as you said. I define a dimens.xml in values-swXdp. Even when the screen is not in split screen , app takes dimensions from values-sw255dp. I want the app to take values from different folders based on screen size. – Vinay Dec 17 '19 at 09:31
  • You probably need to create more folders, like this: https://stackoverflow.com/a/51709197/2910520 and you should test on which folder your device fall to, this depends on the screen DP available – MatPag Dec 17 '19 at 10:55