I have a project when I tried to make app supporting multiple screen size it didn't work the size looks very large in some mobiles and very small in others. So I made a test project I used Smallest screen width I made dimens.xml file for (320dp, 480dp, 600dp, 720dp) and the same for activity_main.xml, I put textView in every xml file like shown in picture to know which file the mobile will read from. the problem is that I have tested it on about 10 mobiles from different screen sizes and versions but all are reading from (320dp) what am I doing wrong?
Asked
Active
Viewed 678 times
1

Archulan Rajakumaran
- 440
- 1
- 6
- 13

Mohamed Wessam
- 167
- 2
- 12
-
Which layout are you using? – Anchit Aug 19 '19 at 10:15
-
what are your layout folder names ? – Manohar Aug 19 '19 at 10:18
-
which devices you tested on, for example? – Vladyslav Matviienko Aug 19 '19 at 10:18
-
if you main the type of layout , in this test project I used ConstraintLayout – Mohamed Wessam Aug 19 '19 at 10:19
-
@MohamedWessam Use of LinearLayout is much preferable. The ConstraintLayout works for pixel to pixel which may vary from device to device. On the other hand, the LinearLayout places objects on screen relative to other objects. Please give it a try and let me know if it works. – Anchit Aug 19 '19 at 10:22
-
@ManoharReddy they are as shown in pic activity_main.xml, activity_main.xml(320dp), activity_main.xml(480dp) etc – Mohamed Wessam Aug 19 '19 at 10:27
-
@Anchit it gives me the same result – Mohamed Wessam Aug 19 '19 at 10:31
-
I want to see layout folder names not layout names , Open in project view and tell folder names – Manohar Aug 19 '19 at 10:31
-
@VladyslavMatviienko Oppo f5, sonny xperia z1, hawawi b9, galaxy s7 and more – Mohamed Wessam Aug 19 '19 at 10:33
-
@ManoharReddy layout, layout-sw320dp, layout-sw480dp, layout-sw600dp, layout-sw720dp. – Mohamed Wessam Aug 19 '19 at 10:36
-
1try this https://stackoverflow.com/questions/49630287/android-layout-size-issue-when-changing-device-settings/49631729#49631729 – Khyati Chitroda Aug 19 '19 at 10:45
-
sw480 is very huge number , are you sure the phone you are using have width of 480dp ? – Manohar Aug 19 '19 at 11:04
-
Of course they are going to read the values from sw320dp because the devices are most likely have the density closer to 320dp. 600dp and above is defined for tablets, try using sw180dp, sw240dp etc... and you will see the difference. – Furkan Yurdakul Aug 19 '19 at 11:09
-
probably none of the devices you listed has width more than 480dp. For example S7 has 360 DP width. – Vladyslav Matviienko Aug 19 '19 at 11:09
-
1Here you can check some devices list: https://material.io/resources/devices/ – Vladyslav Matviienko Aug 19 '19 at 11:12
1 Answers
2
To ensure that your layout is flexible and adapts to different screen sizes, you should use "wrap_content" and "match_parent" for the width and height of most view components, instead of hard-coded sizes.
"wrap_content" tells the view to set its size to whatever is necessary to fit the content within that view.
"match_parent" makes the view expand to as much as possible within the parent view.
FOR EXAMPLE:
android:layout_width="match_parent"
android:layout_height="wrap_content"
AND android:text="" must be hard-coded or resource of string.
Thanks.

Waqar Farooqui
- 81
- 2