tags:

views:

118

answers:

2

How to change the size of height and width according to the screen size?

A: 

If you only want to change the width and height of a standard view I would recommend trying a completely other approach.

Android apps will run on many different screen sizes. You can't write your code to check for each different size and change the layout. However it is possible to define your layout in a relative way that will adapt to changes in the screen size or orientation.

Main ideas for a relative layout are:

  • Don't use an absolute layout.
  • Dont use px values those are absolute. Use dip values these will be 1px on a standard screen and will be increased in size if your screen gets bigger.
  • Use stretchable images in the 9patch format to allow your images to grow or shrink accordingly.
  • If your have difficulties building a layout that adopts try to build a relative layout. That is the most flexible one that allows the most tweaking for correct displaying your content.
  • If everything fails try to build different layout files and different images for different solutions.

For further information read the Supporting Multiple Screens section in the android documentation.

Janusz
A: 

It depends on what you mean by changing the height and width according to the screen size but you should take a look to LayoutParams (layout_height, layout_width, layout_weight, ...) But without any other code, we can't help you

fedj