首页 文章

如何在视图下添加布局

提问于
浏览
0

我想在TextView下方和Button上方添加相对布局 . 我的按钮位于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>

我的相对布局(包含TextView和EditText)位于父布局(RelativeLayout)中,位于iWantLabel下方,位于包含按钮的线性布局上方 . 如何实现这一目标

1 回答

  • 0

    你几乎了解一切,只需要一点关注 . 1)您需要提及所有布局相对于其他视图的位置,如下方或上方所示 . 因为他们的一些高度是fill_parrent,当没有清楚地提到这个地方时会引起问题(与其他人重叠)2)你需要给你的线性布局一个id 3)你需要使用layout_below和layout_above来设置相对布局的位置

相关问题