centering checkbox group

Put your problem here if it does not fit any of the other categories.

centering checkbox group

Postby cybohemia » Sun Mar 09, 2008 3:45 am

Hi! I want to center a group of check boxes and I think I'm missing something basic because I'm just not getting it. Can anyone take a look? Thanks!

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout
  2.  
  3.                 android:orientation="horizontal"
  4.  
  5.                 android:layout_width="fill_parent"
  6.  
  7.                 android:layout_height="wrap_content"
  8.  
  9.                 android:layout_centerHorizontal="true"
  10.  
  11.                 android:layout_gravity="center"
  12.  
  13.                 >
  14.  
  15.                 <CheckBox
  16.  
  17.                         android:id="@+id/box1"
  18.  
  19.                         android:layout_width="wrap_content"
  20.  
  21.                         android:layout_height="wrap_content"
  22.  
  23.                         android:text="box1"
  24.  
  25.                         android:checked="true"
  26.  
  27.                 />     
  28.  
  29.  
  30.  
  31.                 <CheckBox
  32.  
  33.                         android:id="@+id/bxo2"
  34.  
  35.                         android:layout_width="wrap_content"
  36.  
  37.                         android:layout_height="wrap_content"
  38.  
  39.                         android:text="box2"
  40.  
  41.                 />
  42.  
  43. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
cybohemia
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sun Mar 02, 2008 12:21 am

Top

Postby plusminus » Sun Mar 09, 2008 12:11 pm

Hello cybohemia,

to center more than one View, you'll need to create two Dummy-Views to fill the space to the left and right equally, by setting their [font=Lucida Console]android:layout_weight="1"[/font].
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.          android:orientation="horizontal"
  6.  
  7.          android:layout_width="fill_parent"
  8.  
  9.          android:layout_height="wrap_content"
  10.  
  11.          android:layout_centerHorizontal="true"
  12.  
  13.          
  14.  
  15.          >
  16.  
  17.           <TextView
  18.  
  19.            android:layout_width="wrap_content"
  20.  
  21.                 android:layout_height="wrap_content"
  22.  
  23.                 android:layout_weight="1"/>
  24.  
  25.           <CheckBox
  26.  
  27.               android:id="@+id/box1"
  28.  
  29.               android:layout_width="wrap_content"
  30.  
  31.               android:layout_height="wrap_content"
  32.  
  33.               android:text="box1"
  34.  
  35.               android:checked="true"
  36.  
  37.          />  
  38.  
  39.  
  40.  
  41.           <CheckBox
  42.  
  43.               android:id="@+id/bxo2"
  44.  
  45.               android:layout_width="wrap_content"
  46.  
  47.               android:layout_height="wrap_content"
  48.  
  49.               android:text="box2"
  50.  
  51.          />
  52.  
  53.           <TextView
  54.  
  55.            android:layout_width="wrap_content"
  56.  
  57.                 android:layout_height="wrap_content"
  58.  
  59.                 android:layout_weight="1"/>
  60.  
  61. </LinearLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby cybohemia » Sun Mar 09, 2008 6:20 pm

Thanks for the trick, plusminus!

cybohemia
cybohemia
Junior Developer
Junior Developer
 
Posts: 15
Joined: Sun Mar 02, 2008 12:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Majestic-12 [Bot] and 17 guests