Create main menu layout like Robo Defense

Last Updated:

  1. gilangb89

    gilangb89 Member

    First of all, I'm sorry if this is in the wrong section.

    Hi, I'm new to android. I am used to code in C#, and I'm also developing an application for Windows Phone 7. I found out that creating a simple layout in android took a lot more of effort comparing to Windows Phone 7.

    I'm going to create this main menu layout that looks similar to Robo Defense's main menu (the menu where you choose to start game, view achievement, etc).

    note: I already put the
    to the AndroidManifest.xml.

    Check the picture below:


    It was easy to create that kind of main menu in Windows Phone 7, but I had difficulties in Android when trying to design it from the main.xml file.

    I was thinking of using a LinearLayout, and then put a TextView inside the LinearLayout. And after that, I put a TableLayout for the buttons under the TextView. What bugs me is that the table didn't show up, only the text view was displayed.

    Then I changed to using LinearLayout again but then put a TableLayout, then put the TextView inside the TableLayout (into a TableRow), hoping that it would be centered inside the table above the buttons. The result is like this:


    The "Title Bar" isn't centered inside the table, and the table layout creates a tablerow with two elements, one of which is empty, and the rows below it change their widths to fit the rows above them.

    So that's it, i'm stuck here. What should I do? Any help is appreciated, thank you :)

  2. id0001

    id0001 Well-Known Member

    You should handle the drawing and the touch events yourself. Make your app check if a touch event is within a bounding box of an item.
  3. gilangb89

    gilangb89 Member

    thank you, the touch events is not a problem (yet) since those are just buttons, and buttons can be clicked (or touched) without any problems :)

    but that's not what i'm asking for now, i'm curious how to make that kind of layout not how to interact with touch events

  4. kevin@teslacoilsw

    kevin@teslacoilsw VIP Member VIP Member

    I'm guessing you used "fill_parent" in some places where you wanted "wrap_content".

    fill_parent will stretch something, wrap_content will not.
  5. dmitriyk

    dmitriyk Active Member

    Add "android:layout_span=2" to your TextView's XML definition. Right now, the TextView just occupies one column of the table row; the layout_span attribute will make the TextView span both columns.
    cp1 and gilangb89 like this.
  6. gilangb89

    gilangb89 Member

    Hey thanks for the replies, especially dmitriyk. I can now get it working :)

Share This Page