How do I programatically determine which layout (layout-normal, layout-large, etc.) my app is currently using? I see the getWindowManager().getDefaultDisplay().getMetrics(metrics) call but it seems to only deal with screen density but not necessary which layout the app is using. I need the info since I need to programatically change some of the positioning of views dynamically at runtime.
Thanks in advance.
The Constraint layout is the default layout used in Android.
Specifically, Android considers XML-based layouts to be resources, and as such, layout files are stored in the reslayout directory inside your Android project.
xml extension, in your Android project's res/layout/ directory, so it will properly compile. More information about the syntax for a layout XML file is available in the Layout Resources document.
Android Layout is used to define the user interface that holds the UI controls or widgets that will appear on the screen of an android application or activity screen. Generally, every application is a combination of View and ViewGroup.
I had the same problem. If you're using layout
/layout-sw600dp
/layout-sw720dp
, the following ended working for me:
Configuration config = activity.getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 720) {
// sw720dp code goes here
}
else if (config.smallestScreenWidthDp >= 600) {
// sw600dp code goes here
}
else {
// fall-back code goes here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With