1. Download our Official Android App: Forums for Android!

Apps Best way to set up a layout

Discussion in 'Android Development' started by NuffsaidM8, Aug 30, 2016.

  1. NuffsaidM8

    NuffsaidM8 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    18
    Joined:
    Nov 9, 2015

    Nov 9, 2015
    18
    0
    15
    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.
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,726
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,726
    9,467
    1,488
    Male
    Software developer
    South West of England
    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.
     
    HeavensSentSword likes this.
  3. NuffsaidM8

    NuffsaidM8 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    18
    Joined:
    Nov 9, 2015

    Nov 9, 2015
    18
    0
    15
    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.
     
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,726
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,726
    9,467
    1,488
    Male
    Software developer
    South West of England
    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.
     
  5. ac4android

    ac4android Well-Known Member
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    I drag and drop layout widgets onto the Design screen, then edit the XML if I have to, which is almost all the time.
    But at least I have some XML to kick start the layout.
     

Share This Page

Loading...