I have to program my Android app with the best compatibility to different screen sizes (tablets and smartphones) and to the versions 2.3, 3.2 and 4.0. I know about the possibliy to name the folders of the layout like res/layout-sw600dp/. to match the layout exactly to different screen sizes.
So, cause I will use completely different layouts for Tablets / Smartphones, I would start with a "Load Screen", which tests which Android-version is used and if there is used a tablet-or smartphone-device, cause for example in the layout for the Tablet, there will be Buttons on some screens that won't be there on the smartphone.
So I will have to separate all this in packages, like this:
I would choose this separation, cause it's the best way, in my opinion, to be prepared for upcoming *updates*, if, let's say there should be added a Button in the ToolBar in Android 4.0.
Is this separation a good thing in your opinion or is this a complete overload?
Are there any other new features in 4.0 that I should be aware of?
You can use as many layouts as possible for a single activity but obviously not simultaneously. You can use something like: if (Case_A) setContentView(R. layout.
Android Layout TypesTableLayout is a view that groups views into rows and columns. AbsoluteLayout enables you to specify the exact location of its children. The FrameLayout is a placeholder on screen that you can use to display a single view. ListView is a view group that displays a list of scrollable items.
In Android all layout can be nested one another. In this example we create a Registration Form with multiple fields using Nested Linear Layouts. For that we set vertical orientation for parent Linear Layout and horizontal orientation for child Linear Layout.
You can also name your resource folders to indicate version number (like /res/layout-v11
) or (/res/values-v13
)
Regarding your question about separation - it really depends on your particular requirement. A common approach to this problem is a fall-back mechanism: You provide a few specific layouts (for example, an xlarge landscape v11 layout), and a few generic ones to fall back to.
Of course, this is an "idealistic" solution; and it doesn't always work that way. In other words, it is mighty difficult to practically implement an app that is compatible with so many versions of Android solely by providing alternative resources. Even if you use the compatibility libraries (which helps a bit in reducing version-specific code); you will still have to adapt your code based on the version at run-time.
You can find out the Android version looking at Build.VERSION.
The documentation recommends you check Build.VERSION.SDK_INT against the values in Build.VERSION_CODES.
And based on that version you can set your layouts in if else conditions
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