• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Best way to set up a layout

NuffsaidM8

Newbie
Nov 9, 2015
18
0
Just wanted some opinion on a question that has been stifled for a while while I figured things out.

What do you think is the most effective way to go about setting up your layouts?

Do you do all of it with java from the class?

Do you set things up in the XML editor and adjust them with java?

Do you do it all in the XML editor?

Do you do something else?

Any answers are much appreciated.
 
It depends on your app. If you require dynamic layouts, with components being added/removed from the layout at runtime, then this will require code to do it. But for static layouts, then doing it via XML is the most straightforward and easiest method.

If your app requires composite layouts, involving changeable sections on the screen, then consider using Fragments. These are reusable layout components, each having their own XML layout.
 
  • Like
Reactions: HeavensSentSword
Upvote 0
It depends on your app. If you require dynamic layouts, with components being added/removed from the layout at runtime, then this will require code to do it. But for static layouts, then doing it via XML is the most straightforward and easiest method.

If your app requires composite layouts, involving changeable sections on the screen, then consider using Fragments. These are reusable layout components, each having their own XML layout.
Thanks for the response! Follow up question then, since I already had surmised most of that. If I want to have a static layout, but make sure it fit any screen size of someone's phone, would I want to use only XML, only Java, or both?

Thanks again.
 
Upvote 0
Thanks for the response! Follow up question then, since I already had surmised most of that. If I want to have a static layout, but make sure it fit any screen size of someone's phone, would I want to use only XML, only Java, or both?

Thanks again.

This is why it's not advisable to use absolute sizes (in pixels) for your components' width and height. Review this

https://developer.android.com/training/multiscreen/screensizes.html

There are also mechanisms in place to allow you to create different layouts for the various device forms - phone, tablet etc. And you can (and probably should) create different layouts for landscape vs portrait orientation.

The bottom line is, there may not be a 'one size fits all' layout for your app, and you will probably decide to do things differently for small screens vs bigger screens.
Quite often, apps are specifically targeted at device types, to avoid the hassle of developing and maintaining multiple layout formats.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones