要增加列表视图高度,我使用exbandable ListView as,
public class ExpandableListView extends ListView {
private android.view.ViewGroup.LayoutParams params;
private int old_count = 0;
public ExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
if (getCount() != old_count) {
old_count = getCount();
params = getLayoutParams();
params.height = getCount() * (old_count > 0 ? getChildAt(0).getHeight() : 0);
System.out.println("params h "+params.height+" "+params);
setLayoutParams(params);
}
super.onDraw(canvas);
}
}
layout.xml as,
<com.jems.realtimedata.ExpandableListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="25dp"
android:background="@color/list_back"
android:cacheColorHint="#00000000"
android:divider="@drawable/line"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="10dp"
android:scrollbars="none" />
但是,列表的最后一项没有正确显示。我也使用了实用程序类,但list中没有变化。还有其他解决方案来扩展视图。请帮我解决这个问题。
答案 0 :(得分:2)
更改行
params.height = getCount() * (old_count > 0 ? getChildAt(0).getHeight() : 0);
到此:
params.height = getCount() * (old_count > 0 ? getChildAt(0).getHeight() + 1 : 0);
这仅适用于包含单行项目的列表。
答案 1 :(得分:1)