2012-02-12 107 views
0

我很新的相對佈局和我與他們掙扎;)的Android RelativeLayout的煩惱

我所試圖做的是: http://pineapple.cc/plan.jpg

但我得到的是: http://pineapple.cc/result.jpg

這是我的代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 
    <ImageView 
     android:id="@+id/list_poi_image" 
     android:src="@drawable/ic_launcher" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/list_poi_ll" 
     android:background="#000000" /> 
    <LinearLayout 
     android:id="@+id/list_poi_ll" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:orientation="vertical"> 
     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView android:id="@+id/list_poi_name" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/list_poi_date_created" 
       android:text="Name"/> 
      <TextView android:id="@+id/list_poi_date_created" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:text="Date created"/> 
     </RelativeLayout> 
     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 
      <TextView android:id="@+id/list_poi_description" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/list_poi_date_planned" 
       android:text="Description"/> 
      <TextView android:id="@+id/list_poi_date_planned" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:text="Date planned"/> 
     </RelativeLayout> 
    </LinearLayout> 
</RelativeLayout> 

我在做什麼錯???

感謝您的幫助!

回答

1

如果你想使用RelativeLayouts到最好有能力,有沒有必要有其他RelativeLayouts/LinearLayouts內RelativeLayouts/LinearLayouts。

有關如何使用RelativeLayouts例子看看:

http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

在是你想找的以下燕鷗,你在找什麼:

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

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@+id/image" 
     android:text="Name" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/description" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/name" 
     android:layout_below="@+id/name" 
     android:text="Description" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/date_created" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/name" 
     android:layout_alignBottom="@+id/name" 
     android:layout_alignParentRight="true" 
     android:text="DateCreated" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/date_planned" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"    
     android:layout_alignBaseline="@+id/description" 
     android:layout_alignBottom="@+id/description" 
     android:layout_alignParentRight="true" 
     android:text="DatePlanned" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

</RelativeLayout> 

請注意,硬編碼的字符串可以讓你看到文本。確保您刪除這些並使用strings.xml文件。

+0

謝謝了很多,我不知道相對的佈局是如此「強大」,現在我明白如何使用它們更多 非常感謝您的幫助! (這些字符串用於調試) – user1029309 2012-02-12 17:43:01