2014-01-23 74 views
4

我想使用layout_weight屬性進行測試。它對ListView的工作很好。我已將高度設置爲0dp和權重。我試圖把ListView放入一個相對的佈局,但我得到了相同的結果。在這裏我的代碼:Android,ListView layout_weight不工作,高度設置爲0dp

<?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:weightSum="1" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.25" 
    android:text="TextView" /> 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.25" > 
</ListView> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.25" 
    android:text="TextView" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.25" 
    android:text="Button" /> 

</LinearLayout> 

,這是它的外觀:pic

我真的不明白這一點。幫助讚賞。

編輯:它似乎連接到我使用的主題。我正在使用「Theme.Black.NoTitleBar」主題。奇怪的是我可以在模擬器中看到它,但在IDE中看不到它,但是我需要在IDE中看到一些東西,因爲我在GUI中工作很多,並且我正在使用xml進行編碼。有沒有解決這個問題?這是一個已知的錯誤?

+0

嘗試把你的ListView放在另一個LinearLayout中 –

+1

你是否從可視化編輯器,真實設備或模擬器獲得這張圖片?我已經在空項目中檢查了您的佈局,並且它在仿真器上按預期工作 – Dimmerg

+0

並嘗試在設備上運行它,它可能看起來不像IDE所期望的那樣。它適用於我。 –

回答

0

您可以在右上邊框中更改IDE的主題。可能是因爲當前選擇的主題錯過了一些主題。

相關問題