knickelbert
knickelbert

Reputation: 13

How to create such a button group?

I am new to android programming and want to have such a button group:

https://www.dropbox.com/s/4x3l797iwgdaha1/2013-02-20%2020.12.57.png

I tried to create such a layout via the Dashboard-Layout (from the Google IO) but it doesn't look like this, because there is a higher distance ("margins" in a dashboard.

Has anyone a suggestion how to create a "ButtonGroup"-Layout like you see on the screenshot?

Thanks in advance!

knickelbert

Upvotes: 1

Views: 1255

Answers (2)

Vikalp Patel
Vikalp Patel

Reputation: 10887

Add android:padding and android:gravity as when fit to requirement to TableLayout.


 <TableLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:stretchColumns="2"
 android:shrinkColumns="2"
 xmlns:android="http://schemas.android.com/apk/res/android">
  <TableRow>
   <ImageButton 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:src="@drawable/ursrouce"
    />
  <ImageButton 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:src="@drawable/ursrouce"
    />
    </TableRow>
    <TableRow>
    <ImageButton 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:src="@drawable/ursrouce"
    />
   <ImageButton 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:src="@drawable/ursrouce"
    />
   </TableRow>
 </TableLayout>

You can add horizontal and vertical separator as when required after <ImageButton>

Vertical ::

<View
     android:layout_width="1dip"
     android:layout_height="fill_parent"
     android:layout_marginTop="30dp"
     android:layout_marginBottom="30dp"
     android:background="#FF0000FF"
     />

Horizontal ::

<View
     android:layout_width="fill_parent "
     android:layout_height="1dip"
     android:background="#FF0000FF"
     />

Upvotes: 1

Gaurav Arora
Gaurav Arora

Reputation: 1815

If you want to make this generic format, you can use a TableLayout with Two Rows and each row having two columns else a gridview with number of columns set to 2 can also give you the similar appearance.

Upvotes: 0

Related Questions