I have this layout
- Linear Layout
- Scroll View
- Relative Layout
- 9x Button
- Relative Layout
- Scroll View
In View like this (3x3 Grid)
+---------+
| o o o |
| o o o |
| o o o |
+---------+
Every button has it's background and no text, background like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/menu_btn1_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/menu_btn1"/>
</selector>
How should I state the layout, so the buttons will be always 3 per line, and will resize so that they will fit the view ?
This should do the trick if you replace it with your mentioned
RelativeLayout
. All you need to do is ids and style:Try this!
SCREENSHOT:
UPDATE:
If you make LinearLayout (android:id="@+id/wrapper" (LOOK CODE BELOW)) with same layout_height and layout_width you will get what you want
Please look at screenshots. In second screenshot the LinearLayout with android:id="@+id/wrapper" have same width and height and equals 300dp
Try it please! Hope it help you!!
You can use a
TableLayout
that fills the screen and nest it in aScrollView
. Then you can inflate programmatically 3 views in aTableRow
and add that toTableLayout
, like this you will get 3 views per row. Repeat this 3 times and you got what you asked for.Note that if you do that programmatically you can change the order of the buttons pretty easy
Good luck, Arkde