Android:RelativeLayout中的空间组件如何均匀?

我试图组织3个LinearLayouts,这样一个是左对齐,一个是右对齐,而第三个是两个之间,两边有相等数量的空白.我想我将它们包装在RelativeLayout中来实现这一目标.然后将一个布局设置为alignParentLeft,将第二个布局设置为alignParentRight.但是对于第3个布局,我想设置layout_marginLeft =(RelativeLayout.width – (layout1.width layout2.width layout3.width))/ 2.虽然,我不知道如何在xml中执行此操作.有什么建议?

*编辑.基于建议,我现在使用LinearLayout.这更接近于工作,但3个布局不是均匀间隔,并且正确的布局不正确.下面是我的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>

解决方法

使用LinearLayout而不是RelativeLayout并使用layout_weight属性.
您可能需要将layout_width设置为0dip,然后将权重设置为0.33

编辑:
是的,您可以使用重量1或任何其他低于1的相同重量.

<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 for 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 for 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 for test...."
            />
    </LinearLayout>
</LinearLayout>

相关文章

ADB Remote ATV Android TV 的遥控器,基于 ADB Shell 命令 ...
使用Flutter自带的SearchDelegate组件实现搜索界面,通过魔改...
上篇文章讲解了怎么使用Kotlin的协程配合Retrofit发起网络请...
安卓开发——WebView+Recyclerview文章详情页,解决高度...
Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...