我有了一個LinearLayout中爲包含一個TextView和一個ListView像這樣初始化它的頁腳視圖一個ListView:的Android的ListView addFooterView保證金/填充問題
mylist = (ListView) findViewById(R.id.mylist);
mylistadapter = new MyListAdapter(MainView.this, info);
myfooterlistadapter = new MyListAdapter(MainView.this, info);
LinearLayout footer = (LinearLayout)getLayoutInflater().inflate(R.layout.myfooter, null);
myfooterlist = (ListView) footer.findViewById(R.id.myfooterlist);
mylist.addFooterView(footer, null, false);
mylist
聲明爲:
<ListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="0dip" <!-- have also tried fill_parent without weight, same-->
android:layout_weight="1"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:cacheColorHint="#00000000"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false" />
頁腳(LinearLayout中被聲明爲):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/myfooter" >
<TextView
android:id="@+id/myfooterlabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/headermainview"
android:paddingLeft="2dip"
android:text="@string/myfootertext"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
android:visibility="gone" />
<ListView
android:id="@+id/myfooterlist"
android:layout_width="fill_parent"
android:layout_height="0dip" <!-- have also tried fill_parent without weight, same-->
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:dividerHeight="1dip"
android:drawSelectorOnTop="false"
android:visibility="gone"
android:background="@color/green" />
</LinearLayout>
如果我頁腳列表包含項目,我將TextView和頁腳ListView上的可見性更改爲可見。
現在,我在頁腳列表視圖上繪製背景綠色以查看問題(遺憾地隱藏文本,但它是機密信息)。正如你所看到的,我在頁腳列表的底部不斷獲得額外的餘量。我嘗試從fill_parent改爲wrap_content爲0dip,列表和LinearLayout的weight = 1,但都沒有工作。如您所見,我沒有任何與在頁腳列表上的最後一項之後添加額外保證金相關的任何內容。 頂部列表中有20項(我已經滾動到屏幕的底部)和我的頁腳名單隻有在這種情況下,1項:
任何想法是怎麼回事,怎麼就不能有這在我的頁腳列表底部的額外餘量?謝謝!
UPDATE:
經進一步檢查,似乎無論第二列表的大小(我添加更多的項目看)的高度保持不變(綠框總是相同的大小)。我更改爲LinearLayout(無重量)和第二個列表上的fill_parent高度,但尺寸仍然相同。 ListView是否動態計算頁腳的高度以知道它有多大?
我添加了一個新的屏幕截圖,更詳細地顯示第二個項目被切斷(頂部列表未延伸到覆蓋整個第二個列表)。
更新2:
經過進一步調查,如果我把我的第2次的ListView(myfooterlist)的高度,以一個特定的高度(比如300dip),那麼第一個列表顯示了整個第二列表時,我滾動到底部。如果我將它設置爲fill_parent或wrap_conent或0dp並添加layout_weight = 1,那麼它會爲我提供與上面所有圖片相同的高度。任何想法如何動態計算高度?
是否有任何特定的原因顯示第二個列表視圖爲頁腳?它可以對齊第一個列表視圖的底部..對吧? – Kameswari
將頁腳部分保留爲獨立的佈局。同時從頁腳佈局中刪除第二個列表視圖。 – GrIsHu
是的,我想滾動到第一個列表的底部,然後顯示TextView和頁腳列表。LinearLayout位於另一個名爲myfooter.xml的文件中。 – iliask