[英]Add a LinearLayout below ListView
實際上它不是 ListView 而是 ExpandableListView 但這並不重要。 通常我會這樣做:
<ScrollView >
<LinearLayout>
<ExpandableListView ... />
<TextView ... />
</LinearLayout>
</ScrollView>
..但我已經讀過在 ScrollView 中使用 ListView 很費事。 我嘗試通過修改 ExpandListAdapter (getChildView()) 來解決這個問題:
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
if(isLastChild){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.extra_info_bottom, null);
}
else{
//get normal item view
}
return view;
}
但是這樣我只能將孩子附加到組中。 如何在任何組的底部附加 LinearLayout?
只需添加以下代碼即可在最后一個 listview 塊中添加線性布局。
View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
itemlist.addFooterView(footerView);
其中 listfooter 是 xml 文件,您可以在其中定義布局控件。
你有什么理由想要在滾動中包含列表視圖嗎? 您的布局執行以下操作沒有意義:
<LinearLayout>
<ExpandableListView ... />
<ScrollView >
<LinearLayout>
<TextView ... />
</LinearLayout>
</ScrollView>
</LinearLayout>
使用此解決方案,您可以在可擴展列表和滾動視圖上使用權重來定義要為列表使用多少屏幕以及為底部線性布局使用多少屏幕。
如果您希望您的線性布局出現在列表的最底部,我建議您使用頁腳而不是 getView 的東西。
無論如何,為了幫助解決您遇到的確切問題,我需要查看您嘗試膨脹的內容的 xml 定義。
嘗試找出導致此錯誤的對象,並使用myObject.getClass().getName()
查找它的真實 className。 所以你可以看到你真正膨脹的對象,並可能解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.