2011-03-08 19 views
0

自定義標題欄我有一個活動擴展ListActivity 我想添加的LinearLayout或RelativeLayout的就行了 像動作遊戲 的頂部,但是當我在XML中添加 列表不顯示,爲什麼?與ListView的

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
<RelativeLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView android:text="1111" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView1"/> 
</RelativeLayout> 
    <ListView android:id="@id/android:list" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_weight="1" 
     android:drawSelectorOnTop="false" android:padding="4dip" /> 
    <TextView android:id="@id/android:empty" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:text="No_data" /> 
</LinearLayout> 

回答

0

傑森,

谷歌已經提供了什麼,你所說的「動作遊戲」在這裏的一個很好的例子:提供http://code.google.com/p/iosched/

完整的源代碼。

祝你好運。

0

您已擴展ListActivity。您只需要擴展普通的Activity並使用ListView而不是ListActivity。

參考鏈接here

這裏是文本,你需要

ListActivity有一個默認的佈局, 包括在屏幕中心的單一,全屏幕列表 的。但是,如果您願意,可以使用 ,您可以通過在onCreate()中使用setContentView()在 onCreate()中設置自己的視圖 來自定義 屏幕布局。要做到這一點,你自己的看法 必須包含一個ListView對象與 id爲「@android:ID /列表」(或列表,如果 它的代碼)

+1

沒有什麼能阻止他在這裏使用ListActivity,佈局錯誤並且不會爲ListView留出空間。 – adamp 2011-03-08 17:03:48

+0

感謝糾正adamp :) – 2011-03-08 17:52:39

+0

沒問題。 :)這是一個相當普遍的問題,這就是爲什麼我們在幾個版本之前將「fill_parent」的名稱更改爲「match_parent」。 「fill_parent」意味着一個類似於layout_weight的行爲,其中很多人會在後面的元素中共享空間,但這實際上意味着「在這個方向上佔用剩下的可用空間」。一旦LinearLayout中的match_parent項的方向相同,所有後續子項的寬度或高度都將爲0,因爲沒有剩餘空間給它們。 – adamp 2011-03-08 21:34:24

1

你的RelativeLayout上面的列表中有FILL_PARENT的高度並且在它下面的列表中留下空間。嘗試在RelativeLayout上爲layout_height設置一個不同的值,或者使用一個恆定的高度或者wrap_content。

您還希望您的根LinearLayout上的orientation =「vertical」。

0

我遇到了同樣的問題,沒有出現任何內容。對我來說,問題在於Android沒有正確地重新充注資源。在這裏添加第二行固定它對我來說:

final boolean useCustomTitle=requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
getWindow().getDecorView();//required to make title show up 
if(useCustomTitle) 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.my_custom_title); 

第二行返回一個視圖,但我不需要它。但是,沒有它,代碼將無法正常工作。如果您需要查找解決方法,可以在線查找Android源代碼。 private TextView mTitleView仍未更新,因此您可以覆蓋setTitle或使用反射。