0

I have developed an app and tested it in an android phone which has a resolution of 480*640, it was just fine. Now I installed that app on samsung galaxy tab 3, now everything is looking too small, how do I make the layout to fit in the device of any resolution?

In the same application, in one of the xml file, I am hard-coding the layout margin as android:layout_marginLeft="5dp", how do I avoid hard-coding?

Thank you for any help..

Akshatha S R
  • 1,237
  • 1
  • 15
  • 30

1 Answers1

1

Things to check in order to solve the problem:

  • Open each one of your xml files with the layouts and make sure that your layout has as less as possible numbers in it. Do not use px (pixels in design) read and understand how dp and sp work and use them wisely and carefully! Prefer wrap_content and match_parent. Read the docs

  • In order to avoid the use of FIXED dimensions see how RelativeLayout works.

  • If you have many image resources think about replacing them with Nine-patch images (in sort, images that can scale themselves in order to fill an area)

  • For image resources that cannon be changed with nine-patch or where you need to improve the way something looks use different images for different screen densities. More about drawable folders here. And here are some tools to help you generate resources.

These are enough to start with, but if you want to write a really good app then read the whole documentation for Designing for Multiple Screens

madlymad
  • 6,367
  • 6
  • 37
  • 68
  • I have xml files in layout folder and layout-xlarge folder(did it by referring to documentation), and I have numbers in xml which are necessary and all those are in dp, I have not used px anywhere in the xml.. but still it is not showing the exact dimensions:( – Akshatha S R Jul 17 '14 at 07:54
  • The base layout is placed in `layout` folder all other folders usually used for very specific cases such as to achieve multi-screen layouts. I try not use any number at all in my layouts, and that makes the screens fit better everywhere! – madlymad Jul 17 '14 at 08:05
  • Ya but the requirement is like that, they are asking to put the margin of 5dp for small phones and 15dp for large, how could I do this? – Akshatha S R Jul 17 '14 at 08:08
  • Sorry to say that but for the mentioned dimensions it seems that they are asking you to write a Non-Android app. See here: https://developer.android.com/design/style/metrics-grids.html – madlymad Jul 17 '14 at 08:35