Android: how evenly space components within RelativeLayout? -


i trying organize 3 linearlayouts, such 1 justified left, 1 right, , 3rd between 2 equal amount of blank space on either side. think wrap these in relativelayout accomplish this. set 1 layout alignparentleft , 2nd layout alignparentright. 3rd layout, set layout_marginleft = (relativelayout.width - (layout1.width + layout2.width + layout3.width))/2. though, don't see how in xml. suggestions?

*edit. based on suggestions, using linearlayout. closer working, 3 layouts not evenly spaced, , right layout not right justified. below xml:

<linearlayout          android:id="@+id/toolbar"         android:orientation="horizontal"         android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:layout_gravity="bottom"         android:paddingtop="4dip"         android:paddingbottom="4dip"         android:background="#50000000"         android:visibility="visible">         <linearlayout             android:orientation="horizontal"             android:layout_width="wrap_content"             android:layout_weight="1"             android:layout_height="wrap_content">                <imagebutton                      android:id="@+id/open"                     android:src="@drawable/open"                     android:layout_width="wrap_content"                      android:layout_height="wrap_content">                </imagebutton>         </linearlayout>         <linearlayout             android:orientation="horizontal"             android:layout_width="wrap_content"             android:layout_weight="1"             android:layout_height="wrap_content">             <imagebutton                  android:id="@+id/prev"                 android:src="@drawable/prev"                 android:layout_width="wrap_content"                  android:layout_height="wrap_content">             </imagebutton>             <textview                 android:id="@+id/totalpages"                 android:text="0 of 0"                 android:layout_gravity="center"                 android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:textcolor="#ffffffff">             </textview>             <imagebutton                  android:id="@+id/next"                 android:src="@drawable/next"                 android:layout_width="wrap_content"                  android:layout_height="wrap_content">             </imagebutton>         </linearlayout>         <linearlayout             android:orientation="horizontal"             android:layout_gravity="right"             android:layout_width="wrap_content"             android:layout_weight="1"             android:layout_height="wrap_content">             <imagebutton                  android:id="@+id/zoomout"                 android:src="@drawable/zoomout"                 android:layout_width="wrap_content"                  android:layout_height="wrap_content">             </imagebutton>             <imagebutton                  android:id="@+id/zoomin"                 android:src="@drawable/zoomin"                 android:layout_width="wrap_content"                  android:layout_height="wrap_content">             </imagebutton>         </linearlayout>     </linearlayout> 

use linearlayout instead of relativelayout , use layout_weight attribute. might need set layout_width 0dip , set weight 0.33

edit: yes can use weight 1 or other equal weight below 1. example

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <linearlayout         android:orientation="vertical"         android:layout_width="0dip"         android:layout_height="fill_parent"         android:layout_weight="1"         >         <textview               android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="string 1 test...."             />     </linearlayout>     <linearlayout         android:orientation="vertical"         android:layout_width="0dip"         android:layout_height="fill_parent"         android:layout_weight="1"         >         <textview               android:layout_width="wrap_content"              android:layout_height="wrap_content"          android:layout_gravity="center_horizontal"             android:text="string 2 test...."             />     </linearlayout>     <linearlayout         android:orientation="vertical"         android:layout_width="0dip"         android:layout_height="fill_parent"         android:layout_weight="1"         >         <textview               android:layout_width="wrap_content"              android:layout_height="wrap_content"          android:layout_gravity="right"             android:text="string 3 test...."             />     </linearlayout> </linearlayout> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -