我正在開發的左滑動菜單的Android應用程序包含了一些LinearLayout
和中間ExpandableListview
這樣的形象的Android ExpandableListView內滾動型不會擴大全高
的ExpandableListview
子視圖包含一個TextView
和一個ListView
下面,ListView的可見性在默認情況下沒有了。當點擊TextView
時,將會看到ListView
。
問題是,當單擊ExpandableListview
的父視圖時,列表的高度也會展開以包裹它的內容。但是當點擊子視圖(也是TextView
)時,列表'高度不會改變,我必須向下滾動才能看到最後一個項目。
要設置ExpandableListview的高度內滾動型,我用這個代碼:
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
if(listItem instanceof SecondLevelExpandableListView)
Log.e("abc", "SecondLevelExpandableListView");
if (listItem instanceof ViewGroup) {
Log.e("abc", "ViewGroup");
listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
的問題截圖
請幫我解決這個問題,我需要的資源列表總是要包裝它的內容。
在此先感謝。
不,我的意思是,列表視圖始終顯示所有項目,不需要滾動。 – Glenn
那麼你可以再試一次你的問題是什麼? –
我的問題是,當我點擊Texview以可見下面的列表時,ExpanableListview的高度不會擴展到包裝它的內容。我希望ExpandableListview的高度也像我點擊它的父視圖時一樣擴展。 – Glenn