0

I would like to know if, with RelativeLayout, you can position 2 or three buttons side by side and their width is evenly set across the view. e.g. If the screen is 300 pixels the buttons will automatically adopt 100 pixels width each (assuming no padding etc).

I can't really provide code... Because I don't know how to do it =0)

Jay Dee
  • 364
  • 1
  • 2
  • 11
  • Looks like you have a Doppelgaenger. http://stackoverflow.com/questions/5917489 – Thane Anthem May 06 '11 at 23:45
  • Yes, I couldn't access my account or remember what login method I had used before... then I remembered. I had done a quick search on Stack but I must of used the wrong key words =0\ – Jay Dee May 07 '11 at 10:07

1 Answers1

4

I would put a linear layout inside your relative layout (assuming you need the relativelayout for something else) with orientation horizontal and give each button equal weight.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="right|center_vertical">

<!--  Some stuff above -->
<LinearLayout android:id="@+id/LinearLayout01" android:layout_height="wrap_content" 
  android:orientation="horizontal"
   android:layout_width="fill_parent" android:layout_alignParentLeft="true">
           <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:id="@+id/btn"
            android:text="left" />
             <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btn1"
            android:layout_weight="1"
            android:text="center"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btn2"
            android:layout_weight="1"
            android:text="right"/>

   </LinearLayout>
   <!--  Or below -->
</RelativeLayout>
jkhouw1
  • 7,320
  • 3
  • 32
  • 24
  • A little annoyed that I'm being called a new user so can't answer my own question for eight hours, but I've cracked it. Similar to what you've said but not exactly. I will post the answer as soon as stack allows me too =0( – Jay Dee May 06 '11 at 23:13
  • With this solution, you'd also want to set the button widths to 0dip. See http://stackoverflow.com/questions/5459168 – Thane Anthem May 06 '11 at 23:47
  • That's pretty much what I'd got. Thank you for answering this question. I think I will leave this post here just in case any one else needs it =0) – Jay Dee May 07 '11 at 10:03