0

I'm using different layouts for different screen size, but using same method for some onClick and based of the screen size i'm using different drawable that should be set for the View that called onClick.

tried by getTag, but i'm not setting them, beacause I don't know what tag to set(they are based on screensize(physical)).

So how i can get that currently application is using layout from layout-large or layout normal?

StupidFox
  • 376
  • 3
  • 19

2 Answers2

1

You can use the Configuration.screenLayout bitmask.

Example:

if ((getResources().getConfiguration().screenLayout & 
    Configuration.SCREENLAYOUT_SIZE_MASK) == 
        Configuration.SCREENLAYOUT_SIZE_LARGE) {
    // on a large screen device ...

}

Taken from "Jeff Gilfelt", Duplicate: How to determine device screen size category (small, normal, large, xlarge) using code?

Community
  • 1
  • 1
Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
0

What exactly are you trying to do? It sounds like you want different images for the same button depending on the layout, which is already supported without having to explicitly know the screen size you're on. You should be able to use qualifiers like drawable-xhdpi, drawable-sw600dp-xhdpi and drawable-sw800dp-xhdpi. If you put the button image in each of those with the same name, give the button that drawable and the system will choose the correct drawable at run-time without needing to explicitly know the size.

If there's some logic in your onClick that needs to know the screen size, that's a different issue, and if you give more detail about what you want to do there, there might be a similar way that the framework already supports it.

frenziedherring
  • 2,225
  • 2
  • 15
  • 23