Reputation: 71
I am working on android application for my embedded project and I am very new to android. I have developed UI which should be suitable for all kind of screens (all resolution) in android.
Below is my code for all kind of resolution:
if ( ((width>=240)&&(width<=320))&&((height>=320)&&(height<=480)) )
{
setContentView(R.layout.xsmall_layout);
}
else if( ((width>=360)&&(width<=480))&&((height>=640)&&(height<=720)) )
{
setContentView(R.layout.small_layout);
}
else if ( ((width>=480)&&(width<=540))&&((height>720)&&(height<=960)) )
{
setContentView(R.layout.medium_layout);
}
else if ( ((width>540)&&(width<=800))&&((height>=1024)&&(height<=1280)) )
{
setContentView(R.layout.vlarger_layout);
}
else if ( ((width>800)&&(width<=1080))&&((height>=1280)&&(height<=1920)) )
{
setContentView(R.layout.x_vlarger_layout);
}
else if ( ((width>=800)&&(width<=1024))&&((height>=480)&&(height<600)) )
{
setContentView(R.layout.wlarger_layout);
}
else if ( ((width>=1024)&&(width<=1280))&&((height>=600)&&(height<=800)) )
{
setContentView(R.layout.x_wlarger_layout);
}
else if ( ((width>=1280)&&(width<=2560))&&((height>800)&&(height<=1600)) )
{
setContentView(R.layout.xx_wlarger_layout);
}
Its working fine, but is it a good practice ? And in my pc(Intel Dual core, 2GB RAM), for the last resolution in the code is not working. I tried 1920x1200 and 2560x1600 . Android emulator is only not running. simply its coming black screen. Is this my PC problem or what..? Help me seniors......
Upvotes: 0
Views: 672
Reputation: 128428
Instead of that you can create different layout folder inside your res
folder like:
layout-land
layout-large
layout-large-land
layout-xlarge
layout-xlarge-land
Keep the name of xml layout file same in every folder but you can mention different dimensions value.
Anyway, here is the test case you can do:
Upvotes: 2
Reputation: 304
Please refer this one: http://developer.android.com/guide/practices/screens_support.html
In this Documentation they have clearly explained about all supporting screen resolution and dpi.
Upvotes: 1
Reputation: 3215
Hi Mars try like this http://developer.android.com/guide/practices/screens_support.html
Here they created these layout folders inside res
and puted same xml
file to each layout:
layout
layout-small
layout-large
layout-xlarge
this thing ll take care for screen size.
i.e for table,smartphones etc
Upvotes: 0