2012-09-05 25 views
0

我有一個主佈局,底部有一個相對佈局。當我嘗試在相對佈局(id:relativelayout)之上放置相對佈局(id:rl)時,它不顯示。但是當我在底部添加邊距時,它會出現在列表視圖中每個項目的頂部。這是我的xml。如何將相對佈局放置在自定義列表視圖的主佈局底部的相對佈局上方?

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

<TextView 
    android:id="@+id/amount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="16dp" 
    android:layout_marginTop="16dp" 
    android:background="#669900" 
    android:padding="5dp" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 




<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/rl" 
    android:layout_above="@+id/relativelayout" 
    android:layout_marginBottom="2dp" > 

    <TextView 
     android:id="@+id/pass_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="16dp" 
     android:background="#669900" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/discount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="16dp" 
     android:background="#FF8800" 
     android:padding="5dp" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/relativelayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 

      android:layout_alignParentBottom="true" 
    android:background="#0099CC" >  <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="16dp" 
     android:layout_marginTop="4dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#FFFFFF" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/locality" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="12dp" 
     android:textColor="#FFFFFF" /> 
</RelativeLayout> 

+0

請修改您的問題,可能其他人很容易理解。我們在談論哪種RelativeLayout? –

回答

0

請提供屏幕截圖或粗糙的畫面,這樣我可以明白什麼ü真正希望現身.....ü也可以嘗試給重力第一相對佈局PARENT_BOTTOM然後給其他相對佈局的參數作爲LAYOUT_ABOVE= "ID OF THE FIRST LAYOUT"

+0

如何將重力設置爲PARENT_ABOVE? –

+0

對不起我輸入錯誤....我編輯答案....請添加一個點擊我的答案,如果它對你有幫助... –

+0

這就是我所做的,看看我的XML。 –

0

佈局改成這樣:

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

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
    </ImageView> 

    <TextView 
     android:id="@+id/amount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:background="#669900" 
     android:padding="5dp" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <RelativeLayout 
     android:id="@+id/relativelayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:background="#0099CC" > 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="16dp" 
      android:layout_marginTop="4dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#FFFFFF" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/locality" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="16dp" 
      android:layout_marginTop="12dp" 
      android:textColor="#FFFFFF" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/rl" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/relativelayout" 
     android:layout_marginBottom="2dp" > 

     <TextView 
      android:id="@+id/pass_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="16dp" 
      android:background="#669900" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:id="@+id/discount" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="16dp" 
      android:background="#FF8800" 
      android:padding="5dp" /> 
    </RelativeLayout> 

</RelativeLayout> 

這是你想要的嗎?

enter image description here

+0

我只是修正了代碼中的錯誤。但如果這不是你想要的,你必須更清楚地解釋它到底是什麼 –

+0

僅供參考我改變的是,當你使用id設置爲參考時,你不能使用'+'符號。像這樣的android:Layout_Above:「@ id/relativelayout」,並在使用它作爲參考之前首先定義id –

+0

@ archie.logic我想將relativelayout(rl)放在relativelayout(relativelayout) –