1

TextView の下とボタンの上に相対レイアウトを追加したいと考えています。私のボタンは LinearLayout にあり、親は RelativeLayout です。

これが私のコードです。

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

    <ImageView
        android:id="@+id/iWantPageLogo"
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:src="@drawable/wic_logo_small" />

    <Button
        android:id="@+id/goButton_iWant"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="@string/go" />

    <EditText
        android:id="@+id/searchAutoCompleteTextView_iWant"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/goButton_iWant"
        android:layout_toRightOf="@id/iWantPageLogo"
        android:hint="@string/search" />

    <TextView
        android:id="@+id/iWantLabel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/iWantPageLogo"
        android:gravity="center_vertical|center_horizontal"
        android:text="@string/iWant"
        android:textColor="@color/white" />

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:="@+id/iWantLabel">

        <TextView
            android:id="@+id/iNeedToBuy"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/iWantPageLogo"
            android:gravity="center_vertical|center_horizontal"
            android:text="@string/iNeedToBuy"
            android:textColor="@color/white" />

        <EditText
            android:id="@+id/iNeedToBuyEditText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/iNeedToBuy"
            android:hint="@string/product"
            android:textColor="@color/black" />
    </RelativeLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/feedButton_feed"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_margin="0dp"
            android:layout_weight="1"
            android:background="@color/white"
            android:text="@string/feed"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/iWantButton_feed"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_margin="0dp"
            android:layout_weight="1"
            android:background="@color/white"
            android:text="@string/iwant"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/shareButton_feed"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_margin="0dp"
            android:layout_weight="1"
            android:background="@color/white"
            android:text="@string/share"
            android:textColor="@color/black" />

        <Button
            android:id="@+id/profileButton_feed"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_margin="0dp"
            android:layout_weight="1"
            android:background="@color/white"
            android:text="@string/profile"
            android:textColor="@color/black" />
    </LinearLayout>

</RelativeLayout>

親レイアウト(RelativeLayout)にある私の相対レイアウト(TextViewとEditTextを含む)は、iWantLabelの下、ボタンを含む線形レイアウトの上にあります。これを達成する方法

4

1 に答える 1

1

あなたはほとんどすべてを知っており、ほんの少しの注意が必要です。1) 他のビューに対するすべてのレイアウトの位置を下または上に示す必要があります。高さの一部は fill_parrent であるため、場所が明確に言及されていない場合に問題が発生します (他のものと重複する) 2) 線形レイアウトに ID を指定する必要があります 3) layout_below と layout_above を使用して相対的なレイアウトの場所を設定する必要があります

于 2012-04-17T07:31:39.853 に答える