2012-04-17 167 views
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和线性布局,其包含按钮上方。如何实现这一点

回答

0

你几乎都知道一切,只需要一点点关注。 1)您需要提及所有布局相对于其他视图的位置,如下所示。因为他们的一些高度是fill_parrent,导致出现问题(与其他人重叠),当地方没有明确提到时 2)你需要给你的线性布局编号 3)你需要使用layout_below设置相对布局的位置和layout_above