2012-02-12 105 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