2011-11-16 61 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>