Home > Net >  How to place two Linear Layout on each other?
How to place two Linear Layout on each other?

Time:02-15

I try to develop a game using Kotlin where you shall guess a random word. I'd like a "keyboard" for the guessing where the raws of the keyboard would be Linear Layouts with full of Buttons. Something like this:

A B C D E * F G H I J * . . . . .,

where A,B,C,D,E are 5 Buttons contained by a Linear Layout. At the * sign the Linear Layout ends and from F-J there is an another Linear Layout. They shall be under each other and not next to each other.

I cannot place a linear layout to another one because they overlap. I tried RelativeLayout, tried LinearLayout with aligning the Top to the other Linear Layout's bottom, but nothing helped so far.

CodePudding user response:

simplest solution would be to use LinearLayout with orientation set to vertical, which can containt multiple orientation=horizontal LinearLayouts (for each row of letters)

but there are better Views for such purpose, e.g. GridLayout, GridView, TableLayout...

CodePudding user response:

You can use a TableLayout, something like this:

<TableLayout>
     <TableRow>
         <LinearLayout android:orientation="vertical">
            <!-- the views you need here -->
         </LinearLayout>

     </TableRow>

</TableLayout>

You have the table, and for every TableRow you put, you can use a vertical oriented LinearLayout to put the TextView, Buttons or whatever you need

  • Related