【发布时间】:2017-02-01 19:30:35
【问题描述】:
我正在尝试计算可扩展列表视图的高度,以便我可以显示包括标题在内的所有项目,这样用户就不必滚动查看内容。
这是我显示列表视图的片段。旁边是日历:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.DashboardFragment">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".fragments.DashboardFragment">
<ExpandableListView
android:id="@+id/lvExp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="292dp" />
</LinearLayout>
</LinearLayout>
我正在计算位于片段上的 setOnGroupExpandListener 中的高度。首先,我得到两个孩子的高度作为标题:
height += ((expListView.getChildAt(0).getHeight()+expListView.getDividerHeight())-expListView.getDividerHeight())*listAdapter.getGroupCount();
然后我使用下一个公式计算孩子的身高:
for (int i = 0; i < listAdapter.getGroupCount();i++){
if (expListView.isGroupExpanded(i)){
height += listAdapter.getChildrenCount(i)*(expListView.getChildAt(0).getHeight()+expListView.getDividerHeight())-expListView.getDividerHeight();
}
}
当我展开第一组时,列表视图和日历之间会出现一个间隙。当我扩大第二组时,它们之间的差距更大。
我有相同的公式来折叠它们。
我应该使用另一个公式来计算高度吗?
【问题讨论】:
标签: android listview height expandablelistview