使用多个线性布局和权重

时间:2018-08-22 12:00:01

标签: android xml

desired layout

我在实现Android Studio中的布局(如上图所示)时遇到困难。我不想以dp来指定高度和权重,因为我希望布局能够填充它可能在其上显示的任何父级的宽度,但是我不确定如何为每个线性布局指定权重

谢谢

1 个答案:

答案 0 :(得分:0)

我不太确定您想要什么,但是使用权重可以实现目标。

使用这样的布局,您可以处理侧面的图像,中间的textView或editTexts:

 <LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="abc"
        />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="def"
        />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

</LinearLayout>

如果要使用多个线性布局,可以将所需结果的其他部分添加到单独的布局中。

相关问题