Place 2 Radio Buttons beside each other in Relative Layout.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Place 2 Radio Buttons beside each other in Relative Layout.

Postby bluesqrl » Mon Jun 15, 2009 10:16 am

Hello. I'm trying to develop a very simple calculator app to get used to Android. The XML Layout that I've pasted below displays

EDIT BOX

RADIO BUTTON
RADIO BUTTON

EDIT BOX

TEXT VIEW

BUTTON

WHat I actually want is to have the 2 radio buttons beside each other, i.e.

RADIO BUTTON RADIO BUTTON



Could someone please help me to see what I'm doing wrong?



Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="fill_parent">
  8.  
  9.  
  10.  
  11. <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/EditText_Val1"></EditText>
  12.  
  13.  
  14.  
  15. <RadioGroup android:layout_below="@id/EditText_Val1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioGroup_Operators">
  16.  
  17. <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioButton_Plus" android:text="+"></RadioButton>
  18.  
  19. <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/RadioButton_Plus" android:layout_alignTop="@+id/RadioButton_Plus" android:id="@+id/RadioButton_Minus" android:text="-"></RadioButton>
  20.  
  21. </RadioGroup>
  22.  
  23.  
  24.  
  25. <EditText android:layout_below="@id/RadioGroup_Operators" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/EditText_Val2"></EditText>
  26.  
  27.  
  28.  
  29. <TextView android:layout_below="@id/EditText_Val2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/TextView_Result"></TextView>
  30.  
  31.  
  32.  
  33. <Button android:layout_below="@id/TextView_Result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Calculate" android:id="@+id/Button_Calculate"></Button>
  34.  
  35.  
  36.  
  37. </RelativeLayout>    
  38.  
  39.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
bluesqrl
Freshman
Freshman
 
Posts: 2
Joined: Mon Jun 15, 2009 10:11 am

Top

Postby egyptian » Mon Jun 15, 2009 5:02 pm

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <TableLayout
  5.  
  6.         xmlns:android="http://schemas.android.com/apk/res/android"
  7.  
  8.         android:layout_width="fill_parent"
  9.  
  10.         android:layout_height="fill_parent">
  11.  
  12.         <EditText
  13.  
  14.                 android:layout_width="wrap_content"
  15.  
  16.                 android:layout_height="wrap_content"
  17.  
  18.                 android:id="@+id/EditText_Val1"></EditText>
  19.  
  20.         <RadioGroup
  21.  
  22.                 android:layout_below="@id/EditText_Val1"
  23.  
  24.                 android:layout_width="wrap_content"
  25.  
  26.                 android:layout_height="wrap_content"
  27.  
  28.                 android:id="@+id/RadioGroup_Operators">
  29.  
  30.                 <TableLayout
  31.  
  32.                         android:id="@+id/TableLayout01"
  33.  
  34.                         android:layout_width="wrap_content"
  35.  
  36.                         android:layout_height="wrap_content">
  37.  
  38.                         <TableRow
  39.  
  40.                                 android:id="@+id/TableRow01"
  41.  
  42.                                 android:layout_width="wrap_content"
  43.  
  44.                                 android:layout_height="wrap_content">
  45.  
  46.                                 <RadioButton
  47.  
  48.                                         android:layout_width="wrap_content"
  49.  
  50.                                         android:layout_height="wrap_content"
  51.  
  52.                                         android:id="@+id/RadioButton_Plus"
  53.  
  54.                                         android:text="+"></RadioButton>
  55.  
  56.                                 <RadioButton
  57.  
  58.                                         android:layout_width="wrap_content"
  59.  
  60.                                         android:layout_height="wrap_content"
  61.  
  62.                                         android:layout_toRightOf="@+id/RadioButton_Plus"
  63.  
  64.                                         android:layout_alignTop="@+id/RadioButton_Plus"
  65.  
  66.                                         android:id="@+id/RadioButton_Minus" android:text="-"></RadioButton>
  67.  
  68.                         </TableRow>
  69.  
  70.                 </TableLayout>
  71.  
  72.         </RadioGroup>
  73.  
  74.         <EditText
  75.  
  76.                 android:layout_below="@id/RadioGroup_Operators"
  77.  
  78.                 android:layout_width="wrap_content"
  79.  
  80.                 android:layout_height="wrap_content"
  81.  
  82.                 android:id="@+id/EditText_Val2"></EditText>
  83.  
  84.         <TextView
  85.  
  86.                 android:layout_below="@id/EditText_Val2"
  87.  
  88.                 android:layout_width="wrap_content"
  89.  
  90.                 android:layout_height="wrap_content"
  91.  
  92.                 android:id="@+id/TextView_Result"></TextView>
  93.  
  94.         <Button
  95.  
  96.                 android:layout_below="@id/TextView_Result"
  97.  
  98.                 android:layout_width="wrap_content"
  99.  
  100.                 android:layout_height="wrap_content"
  101.  
  102.                 android:text="Calculate"
  103.  
  104.                 android:id="@+id/Button_Calculate"></Button>
  105.  
  106. </TableLayout>  
Parsed in 0.007 seconds, using GeSHi 1.0.8.4


Using tablelayout is much better for a calculator.
Without God, I would not have ANY skills.
egyptian
Developer
Developer
 
Posts: 36
Joined: Fri Jan 16, 2009 5:45 am
Location: Lee's Summit, Missouri

Postby nmc » Mon Jun 15, 2009 7:30 pm

Did you try the obvious solution?

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <RadioGroup android:id="@+id/rg"
  3.  
  4.         android:layout_width="fill_parent"
  5.  
  6.         android:layout_height="wrap_content"
  7.  
  8.         android:layout_below="@+id/otherControl"
  9.  
  10.         android:orientation="horizontal">
  11.  
  12.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby egyptian » Mon Jun 15, 2009 7:45 pm

nmc wrote:Did you try the obvious solution?

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <RadioGroup android:id="@+id/rg"
  2.         android:layout_width="fill_parent"
  3.         android:layout_height="wrap_content"
  4.         android:layout_below="@+id/otherControl"
  5.         android:orientation="horizontal">
  6.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


When I pasted the code into Eclipse, I saw that all the items were sitting on top of each other. That's why I figured guiding him/her towards a tablelayout.
Without God, I would not have ANY skills.
egyptian
Developer
Developer
 
Posts: 36
Joined: Fri Jan 16, 2009 5:45 am
Location: Lee's Summit, Missouri

Thank you!

Postby bluesqrl » Tue Jun 16, 2009 7:36 am

Hello.

Thank you to both of your for your postings. I can now see a simple way to have quickly achieved what I wanted as well as the more adaptable complex solution in the table. I'm new to Android so any help that I get is very well received. Thank you again, I do appreciate both of your solutions!

Thanks,

BlueSqrl
bluesqrl
Freshman
Freshman
 
Posts: 2
Joined: Mon Jun 15, 2009 10:11 am

Postby nmc » Tue Jun 16, 2009 10:14 am

When I pasted the code into Eclipse, I saw that all the items were sitting on top of each other.


When using relative layouts, you have to set a position for the buttons like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <RadioButton android:id="@+id/Radio2"
  2.         android:layout_height="wrap_content"
  3.         android:layout_width="wrap_content"
  4.         android:text="2"
  5.         android:layout_toRightOf="@+id/Radio1"
  6. />
  7.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests