2012-09-02 40 views
0

我想將4個對象放置在列表視圖項目的四個角落中。我正在使用相對佈局。出於某種原因,這些物體只與左側對齊。 2個對象應該在右邊。我也使用layout_gravity,但沒用。他們都對齊左側。Android 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="wrap_content" > 

    <include 
     android:id="@+id/fromDistanceWindowLayout" 
     android:layout_alignParentLeft="true" 
     android:layout_gravity="left" 
     layout="@layout/include_distance_window" /> 

    <include 
     android:id="@+id/toDistanceWindowLayout" 
     android:layout_alignParentRight="true" 
     android:layout_gravity="right" 
     layout="@layout/include_distance_window" /> 

    <include 
     android:id="@+id/fromTimeWindowLayout" 
     android:layout_alignParentLeft="true" 
     layout="@layout/include_time_window" /> 

    <include 
     android:id="@+id/toTimeWindowLayout" 
     android:layout_alignParentRight="true" 
     layout="@layout/include_time_window" /> 

包括include_distance_window.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/distancebackground" 
      android:layout_alignParentTop="true" /> 

     <TextView 
      android:id="@+id/distanceWindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" /> 
    </RelativeLayout> 

包括include_time_window

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/distancebackground" /> 

<TextView 
    android:id="@+id/timeWindow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="123"/> 

編輯: 如果我更換第二包括與包含內容的XML它一切正常

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/distancebackground" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/distanceWindow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 
</RelativeLayout> 

我想知道爲什麼?

回答

1

我想指出的一件事。佈局重力對相對佈局沒有影響。它是線性佈局的參數。第二,如果您使用的是Eclipse IDE,請檢查圖形佈局。我想知道你是否能夠看到所有相關的佈局?我想不是給相對佈局的包裝內容,你可以嘗試給出一些確定的值,比如70dp。請嘗試這些,修補和讓我知道這些變化。

+1

明智的變化。是的,這有所改變,孩子們開始在角落裏做。是的,重力沒有區別。 – Siddharth

+0

我剛剛完成了類似的事情。很高興幫助:D。時機和情況。 –