LinearLayout有两个宽度相等的子节点

boz*_*boz 12 android android-layout

我有一些问题让两个孩子的a LinearLayout具有相同的宽度.这就是我得到的:

截图

这是灰色框的布局xml:

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2"
    android:background="@color/medium_grey"
    >

    <ImageView 
        android:id="@+id/profile_photo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:src="@drawable/placeholder_profile_photo"
        android:scaleType="fitCenter"
        android:contentDescription="@string/blank"
        android:layout_weight="1"
        />

    <LinearLayout 
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_weight="1"
        android:layout_gravity="center_vertical"
        android:background="@color/alert"
        >

        <TextView
            android:id="@+id/profile_rate_header"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Rate User"
            />

        <LinearLayout 
            android:id="@+id/profile_action_rate_user"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:gravity="center"
            >

            <ImageView 
                android:id="@+id/profile_action_rate_up"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/user_rate_up"
                />

            <ImageView 
                android:id="@+id/profile_action_rate_down"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/user_rate_down"
                />

        </LinearLayout>
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我假设设置layout_weight根的子项LinearLayout以及a weightSum和宽度0dp将产生所需的效果(图像与粉红色'率用户'部分的大小相同)但是情况并非如此.

我错过了什么?

编辑:

这就是我想要它的样子

在此输入图像描述

照片和粉红色的线性布局应该是相等的宽度.

SK9*_*SK9 27

android:weightSum="2"应该是两个子ImageViews的父级,而不是上级父级.或者尝试设置权重0.5,看看它是否有效.

此外,两个图像视图的宽度应该是android:layout_width="0dp"在使用这样的权重时.

接下来,放大图像以填充空间.细节在这里.


dre*_*per 12

同等重视儿童

要创建一个线性布局,其中每个子节点在屏幕上使用相同的空间量,请将每个视图的android:layout_height设置为"0dp"(对于垂直布局)或将每个视图的android:layout_width设置为"0dp"(用于水平布局).然后将每个视图的android:layout_weight设置为"1".请参阅:http://developer.android.com/guide/topics/ui/layout/linear.html