2010-03-22 147 views
0

我有问题让我的一些视图对齐在我的列表视图中使用的相对布局。为什么我的一些视图在我的相对布局的底部没有正确对齐?

下面是Eclipse中的布局构建一个截图,这是我认为它应该是这样的:

alt text http://janusz.de/~janusz/eclipse.png

下一个图像是从仿真器。现在TestTestTest视图位于顶部,涵盖了Textviews的名称和距离。

alt text http://janusz.de/~janusz/emulator.png

这是我的布局:

<?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" 
android:padding="4dip"> 

<ImageView android:id="@+id/logo" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:adjustViewBounds="true" 
    android:scaleType="centerInside" android:src="@drawable/icon" 
    android:layout_centerVertical="true" android:layout_alignParentLeft="true" 
    android:background="@color/green" /> 

<TextView android:id="@+id/distance" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="Distance" 
    android:layout_alignParentRight="true" android:layout_alignParentTop="true" 
    android:paddingRight="4dip" android:background="#000000" /> 

<TextView android:id="@+id/name" android:layout_width="fill_parent" 
    style="@style/ListHeadText" android:layout_height="wrap_content" 
    android:text="Name" 
    android:layout_alignTop="@id/distance" android:layout_toRightOf="@id/logo" 
    android:layout_toLeftOf="@id/distance" android:gravity="clip_horizontal" 
    android:lines="1" android:paddingLeft="4dip" android:background="@color/red" /> 

<TextView android:id="@+id/number" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="Number" 
    android:paddingRight="4dip" android:layout_alignRight="@id/distance" 
    android:background="@color/darkred" android:layout_below="@id/distance" /> 

<TextView android:id="@+id/subcategory" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="Subcategory" 
    android:paddingLeft="4dip" android:layout_alignLeft="@id/name" 
    android:lines="1" android:gravity="clip_horizontal" 
    android:layout_below="@id/distance" android:background="@color/green" /> 

<TextView android:id="@+id/test" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="TestTestTest" 
    android:paddingLeft="4dip" 
    android:layout_alignParentBottom="true" android:gravity="bottom" 
    android:background="@color/red" /> 

不应该align_parent_bottom把视图在列表中的单元格的底部?

回答

1

尝试添加android:layout_alignParentLeft="true"以及;有时视图不能正确显示,如果它不能锚定视图至少2点。此外,这是在一个ListView中使用RelativeLayout?如果是这样,你可能会发现你有一些困难让它看起来不错。 another question有人遇到了一个问题,其中RelativeLayout看起来是正确的,但一旦它被包含为ListView的一部分。我们无法弄清楚出了什么问题,所以他不得不使用嵌套的LinearLayouts。

+0

更改为嵌套的线性布局。 – Janusz 2010-03-26 08:17:43