2011-11-16 128 views
0

我疯了,试图做一个相对的布局工作。当ListView出现问题时,listView总是显示一个空白空间,大约是一个listView元素高度的两倍,如果列表大小足以滚动或不滚动(通常该列表容纳4个元素而不需要滚动) 。带有ListView的RelativeLayout没有正确显示

为了解决这个问题,我试图实现一个RelativeLayout。我有一个TextView在顶部,一个在底部,我的列表视图在中间。在我的列表视图TextView的公司必须“粘”,我用的LinearLayout的空白问题之前,现在我有这个相对布局:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="@drawable/background" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"> 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:orientation="vertical" 
     android:layout_height="fill_parent"> 

    ... 
      <RelativeLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 

       <TextView 
        android:id="@+datatrade/tv_itens" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:text="Itens:" /> 

       <TextView 
        android:id="@+datatrade/tv_value" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Value:" />           

       <ListView android:layout_width="fill_parent" 
        android:layout_height="200px" 
        android:layout_below="@datatrade/tv_itens" 
        android:layout_above="@datatrade/tv_value" 
        android:id="@+id/list_product" 
        /> 

      </RelativeLayout> 
    ... 

的问题是,我刚刚得到显示我的第二个文本视图,与“价值观:”,没有别的! 所有其余的相对布局被android忽略!

有谁知道可能是什么问题?

回答

3
<TextView 
       android:id="@+datatrade/tv_value" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="Value:" /> 

您还没有声明应该显示此文本视图的位置。

+0

我试图与Android的位置:layout_alignParentTop在我的TextView =“真”没有宣布(这个)一切位置还是很喜欢它,只显示这个textView。 – IPValverde

+0

对不起我的问题..你想添加页眉和页脚到列表视图? – Blackbelt

+0

然后你添加与android:layout_alignParentTop =“true”的东西。你尝试过android:layout_alignParentBottom =“true”吗? – Blackbelt

1

试试这个:

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:orientation="vertical" 
     android:layout_height="fill_parent"> 

      <RelativeLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 

       <TextView 
        android:id="@+id/tv_itens" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" 
        android:text="Itens:" /> 

       <TextView 
        android:id="@+id/tv_value" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="Value:" 
        android:layout_below="@+id/list_product"/>           

       <ListView android:layout_width="fill_parent" 
        android:layout_height="200dp" 
        android:layout_below="@+id/tv_itens" 
        android:id="@+id/list_product" 
        /> 

      </RelativeLayout> 
</LinearLayout> 

你需要告诉ListView控件是第一个TextView的下方,那么第二个TextView的是ListView的下方。

此外,您的ID似乎有点奇怪,我在复制代码时收到警告,请尝试使用@ + id来确保。

最后,你不应该使用px作为大小,而应该使用相对的dp。

2

您必须指定每个对象相互关联。否则,相对布局无法理解您放置对象的位置,并且没有相关性。

检查此了解对象以及如何之间的相关性对他们

<?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" 
android:background="#CCE6FF"> 

<ScrollView android:id="@+id/ScrollView01" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"> 

    <TextView android:text="@+id/TextView01" android:id="@+id/dialog_desc_textview" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:textSize="18dip" android:textColor="#000000"/> 

</ScrollView> 

<Button android:id="@+id/dialog_goToDesc_button" android:layout_below="@id/ScrollView01" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:text="Satın Al" /> 

<Button android:id="@+id/dialog_buy_button" android:layout_below="@id/ScrollView01" 
    android:layout_toRightOf="@id/dialog_goToDesc_button" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:text="Detaya git" /> 

<Button android:id="@+id/dialog_cancel_button" 
    android:layout_toRightOf="@id/dialog_buy_button" android:layout_below="@id/ScrollView01" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:text="Kapat" /> 

</RelativeLayout>