Reputation: 177
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?
Upvotes: 1
Views: 838
Reputation: 81
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.
Upvotes: 2