user1384991
user1384991

Reputation: 2629

Providing unique layout for specific resolution in Android 2.3.3

I need to use specific xml-layouts based on screen resolution, not size. So, the first design is used for resolution <= 480x800, and the second - for resolution >= 480x800.

How is it done ?

update.

I've come up with

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    final int height = display.getHeight();
    final int width = display.getWidth();



    int leadingResolutionSize = Math.max(height, width);
    if(leadingResolutionSize <= 800){
        setContentView(R.layout.main);
    }else if(leadingResolutionSize > 800 && leadingResolutionSize <= 1024){
        setContentView(R.layout.main_1024_600);
    }else if(leadingResolutionSize > 1024){
        setContentView(R.layout.main_1280_800);
    }

Do you think it's a good solution ?

Upvotes: 0

Views: 481

Answers (2)

Avadhani Y
Avadhani Y

Reputation: 7646

layout folder in your project contains xml files which can be designed defaultly for PORTRAIT Mode(that is 480*800 in your case). If you want for LANDSCAPE Mode.In the same way declare another folder named as layout-land(that is 800*480) and store the layout xml files in that folder and modify those files based on your requirement.

Upvotes: 0

MAC
MAC

Reputation: 15847

you can create different xml layouts

and put all them in

  • hdpi
  • idpi
  • mdpi
  • xhdpi

for more see this answer

Upvotes: 1

Related Questions