0

I want my app to run perfectly on different screen sizes, Galaxy Tab 2, Galaxy Note 800 and Galaxy Note 2.

However, my app is fairly complex and I can't use wrap_content or fill_parent at all places. I've tried using layout_weight but even that couldn't be used with RelativeLayout.

Is there any smart way of resizing your screen components depending upon screen size other than making different layouts all together as suggested in Android documentation and is there any way to use layout_weight in RelativeLayout?

Thanks!

Ram kiran Pachigolla
  • 20,647
  • 14
  • 56
  • 74
Gaurav Arora
  • 16,664
  • 5
  • 32
  • 44

3 Answers3

1

You can use TableLayout and in that TableRow. I have preferred these to RelativeLayout in one of my project because RelativeLayout does not support weight property as you said.

cirit
  • 490
  • 5
  • 10
0

Its true you cannot use weight with Relative Layout. If you want to make sure your layout runs perfectly for every device. You must use Nested LinearLayouts with views and do that in weight your UI will be perfect if you have good resolution images for every device.

Moreover in RelativeLayout complex layout can't be perfect as you cannot use weight and sometimes images may get skew or stretch .

Of course using Nested LinearLayouts with views do increase some extra lines but this is the only perfect solution.

cirit
  • 490
  • 5
  • 10
Jitender Dev
  • 7,381
  • 2
  • 23
  • 37
  • Using nested layouts uses more resources and increases complexity and isn't an optimized solution. Source: http://developer.android.com/training/improving-layouts/optimizing-layout.html – Gaurav Arora Dec 05 '12 at 11:58
  • @ Infinity In the same doc its mentioned Total time taken for nested layout is 3.861ms and Total time taken for simple layout is 2.854 i.e. a difference of merely 1 ms to draw UI, If you cannot comprise with 1 ms then you can never make complex layuots without using weight and nesting. – Jitender Dev Dec 06 '12 at 10:54
0

I found an efficient way round.

Instead of hard coding dimensions in layout I used a reference of them in Resources/values/dimensions.xml. So, for different screen sizes I simply made different dimension file in Resources, thereby reducing complexity and avoided making separate layouts for all screen sizes.

Gaurav Arora
  • 16,664
  • 5
  • 32
  • 44