Arian
Arian

Reputation: 3241

Layout like Java GridLayout?

Basically I want to get a Layout that behaves like a Java GridLayout.

I tried LinearLayout and TableRow but the elements are always added after each other.

Whats the best way to achieve this (using the xml approach)?

Upvotes: 0

Views: 356

Answers (2)

Arian
Arian

Reputation: 3241

Solved it:

<LinearLayout
    android:orientation="horizontal"    
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" >


    <Button
        android:id="@+id/button1"
        style="@style/ButtonStyle"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/main_buttons"
        android:text="@string/sGet" 
        android:layout_weight="1" />

    <Button
        android:id="@+id/button2"
        style="@style/ButtonStyle"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/main_buttons"
        android:text="@string/sStop"
        android:layout_weight="1" />

    <Button
        android:id="@+id/button3"
        style="@style/ButtonStyle"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/main_buttons"
        android:text="@string/sSettings"
        android:layout_weight="1" />

    <Button
        android:id="@+id/button4"
        style="@style/ButtonStyle"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/main_buttons"
        android:text="@string/sExit"
        android:layout_weight="1" /> 

</LinearLayout>

Upvotes: 0

Vladimir
Vladimir

Reputation: 3812

According to this You can use GridLayout with Support Library

A new Library Project adds support for GridLayout back to API level 7 and higher

Upvotes: 2

Related Questions