1

我无法获得如下所示的布局:

在此处输入图像描述

是否有可能做这样的事情:

<RelativeLayout>

    <TextView
    android:id="@+id/text1"
    android:layout_alignParentLeft="true"/>

    <TextView
    android:layout_below="@id/text1/>

    <LinearLayout
    android:orientation="vertical"
    android:layout_alignRightOf="@id/text1">

        <ImageButton/>
        <ImageButton/>
        <ImageButton/>

    </LinearLayout>

</RelativeLayout>

或者更具体地说,是否可以设置 layout_align on ,如下所示:android:layout_alignRightOf="@id/text1"

如果没有,我该如何获得这个布局?

4

4 回答 4

1

我不知道如何(如果可能的话)使用RelativeLayout,但是使用一些LinearLayout 应该很容易,这里有一个示例:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0000"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#aa0000ff"
            android:layout_weight="1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#aaff0000"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#00ff00"
        android:orientation="vertical" >

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>

</LinearLayout>
于 2013-09-19T18:16:04.870 回答
1

在我看来,这是一个完美的例子LinearLayout。看看 Linearlayouts 的权重属性。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="80dp"
        android:layout_height="240dp"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/ImageButton02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon_plus" />

        <ImageButton
            android:id="@+id/ImageButton01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon_plus" />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon_plus" />

    </LinearLayout>

</LinearLayout>
于 2013-09-19T18:18:55.510 回答
0

创建一个父相对布局,该布局将具有两个子相对布局 1. 第一个子相对布局将具有左侧两个文本视图 2. 第二个子相对布局将具有右侧图像视图

于 2013-09-19T18:14:04.480 回答
0

像这样试试

  <RelativeLayout
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.5"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.5"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <View
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:background="#ff4500"
        android:orientation="vertical" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <Button
            android:id="@+id/textView1"
            android:layout_width="212dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.33"
            android:text="Large Text" />

        <Button
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.33"
            android:text="Large Text" />

        <Button
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_weight="0.33"
            android:text="Large Text" />
    </LinearLayout>
</LinearLayout>
于 2013-09-19T18:25:22.700 回答