Home > Software engineering >  Android studio different screen size open diffrent layout file?
Android studio different screen size open diffrent layout file?

Time:11-28

Layout XML file

activity_one - 360dp above

activity_two - 480dp above

activity_three -600dp above

java file different size different layout

     super.onCreate(savedInstanceState);

    //getSupportActionBar().hide();

    setContentView(R.layout.activity_one);

CodePudding user response:

This would help you :

https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes

The real clean way is create folders for it :

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)

This is cool :

res/layout/main_activity.xml                # For handsets
res/layout-land/main_activity.xml           # For handsets in landscape
res/layout-sw600dp/main_activity.xml        # For 7” tablets
res/layout-sw600dp-land/main_activity.xml   # For 7” tablets in landscape

You can create exclusives layouts for landscape position .

CodePudding user response:

Maybe try It java code more than clear :-

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Configuration config = getResources().getConfiguration();
    if (config.smallestScreenWidthDp >= 320) {
        setContentView(R.layout.activity_one);
    } else if (config.smallestScreenWidthDp >= 480) {
        setContentView(R.layout.activity_two);
    } else if (config.smallestScreenWidthDp >= 600) {
        setContentView(R.layout.activity_three);
   }
  • Related