2014-03-03 31 views
0

最後一行下方仍有一小塊區域爲白色。爲什麼允許下面的代碼發生?在Android中的ListView下方更改空白的顏色

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/lightGray"> 

    <ListView 
     android:id="@+id/home_listview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white" > 
    </ListView> 

</LinearLayout> 

UPDATE:感謝大家的建議。這個問題是因爲我在適配器的getView中膨脹自定義行時所做的奇怪事情。我想我的ListView的行是不同的大小。顯然,列表視圖是通過計算第一行膨脹的高度乘以行數得到其總高度。這導致了一個問題,因爲我所有的行不是相同的大小。我最終根據每行添加的高度動態更改列表視圖的高度。

+1

請問您張貼截圖嗎?在旁註中,我來自克林頓!小世界。 – adneal

+0

也許這是match_parent,我可能會用fill_parent,你試過嗎? – Tomas

+0

Omg,'fill_parent'已經被棄用了,這就是爲什麼他使用'match_parent'。是的屏幕截圖不會是不必要的 –

回答

0

我最終要做的解決方案是讓ListView背景顏色與LinearLayout背景顏色相同,但讓ListView的每一行都成爲我真正想要ListView的顏色。這樣,如果由於高度計算不正確而導致ListView底部有額外的空間,它看起來就像是背景的一部分。此外,藉助此解決方案,我不必擔心對ListView進行動態高度計算。

0

這可能是除法 - 試圖將其設置爲透明(或您選擇的顏色),您也可以改變高度:

<ListView 
     android:id="@+id/home_listview" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="10dp" 
     android:padding="10dp" /> 
0

嘗試改變layout_widthlayout_heightfill_parent

<ListView 
     android:id="@+id/home_listview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/white" > 
    </ListView> 
相關問題