Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make responsive Android application which is used in mobile and also in tablet?

I have created one Android application.

When I run my application in Mobile Phone it works very well, but when I run in Tablet the layout of application is changed.

So, how to make responsive Android application which is used in Mobile and also in Tablet?

like image 317
Sagar Zala Avatar asked Dec 06 '22 03:12

Sagar Zala


1 Answers

On Android we can use screen size selector, introduced from Android 3.2, to define which layout to use. More details available at http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html. Following code snippet has been extracted from the same link :

public class MyActivity extends Activity 
{
    @Override protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate();
        Configuration config = getResources().getConfiguration();
        if (config.smallestScreenWidthDp >= 600) 
        {
            setContentView(R.layout.main_activity_tablet);
        } 
        else 
        {
            setContentView(R.layout.main_activity);
        }
    }
}

Another good reference for size configuration is keeping separator. This is explain in details at : http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf

like image 75
Harshal Doshi Jain Avatar answered Dec 10 '22 13:12

Harshal Doshi Jain