Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:21:45+00:00 2026-06-08T16:21:45+00:00

i use different Layouts for different Screensizes and Devices. I use Fragments with specific

  • 0

i use different Layouts for different Screensizes and Devices. I use Fragments with specific Layout Folders.
The Concept is great, for Tablets and Devices with a Large Screen i place a Layout file in
layout-sw600dp and Android manages to deliver the right layout on the different devices.

What Bugs me is: How can i find out what Layout is used inside my Code.
My Fragments needs slightly different Codes for the different Layouts.

In General whats the Best Practice to separate Custom Layout Programming Logic inside my Fragments/Activities?

My approach now is kind of hacky and not in sync with the different Layout folders.

  private boolean isTabletDevice() {
    if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb
      // test screen size, use reflection because isLayoutSizeAtLeast is
      // only available since 11
      Configuration con = getResources().getConfiguration();
      try {
        Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast", int.class);
        Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
        return r;
      } catch (Exception x) {
        x.printStackTrace();
        return false;
      }
    }
    return false;
  }

and then

if(isTabletDevice()) {
//findViewById(R.id.onlyInTabletLayoutButton);
}else{
//
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:22:01+00:00Added an answer on June 8, 2026 at 4:22 pm

    This is the method I use personally:

    In each layout, I add a Tag to the root of the layout, and make sure that all of the layout roots have the same id. So for example, I’ll have a layout that goes something like:

    <RelativeLayout
    android:id="@+id/rootView"
    android:tag="landscapehdpi">
    <!-- Rest of layout -->
    </RelativeLayout> 
    

    And then have another one like:

    <RelativeLayout
    android:id="@+id/rootView"
    android:tag="portraitmdpi">
    <!-- Rest of layout -->
    </RelativeLayout> 
    

    Then once the layout has been inflated, I use:

    View rootView = (View) findViewById(R.id.rootView);
    

    This returns the layout root currently in use. Now to determine which layout it is exactly and run the appropriate code, I use a series of if-else blocks:

    String tag = rootView.getTag().toString();
    
    if(tag.equals("landscapehdpi"))
    {
    //Code for the landscape hdpi screen
    }
    else if(tag.equals("portraitmdpi"))
    {
    //Code for the portrait mdpi screen
    }
    //And so on...
    

    So basically using this you can know which layout has been loaded at runtime, and run the appropriate code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a venue layout app for the ipad that will use different
Is it possible to use different icons for ICS devices and 3.0 and previous
I use a different layout for some actions (mostly for the new action in
Previously my program was working well on different sizes of screen and devices. After
How can I use JavaScript to display one of two different layouts based on
I'm trying to create a custom cursoradapter that will use two different layouts depending
Suppose you want a Blog with two different layouts. One layout should look like
I wanna use one image ( 1280x800 ) for two device with different screen
Do I need to use different certificates to sign different apps if they are
Can I use different levels in Sentry? my config: 'handlers': { 'sentry': { 'level':

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.