In this post we have learn about to setting a fixed height for List view (i.e) List view having 20 list items. But displaying only 4 items. once we delete the item, the next item has to displayed.
Code:
public void SetCustomHeightForListView(ListView listView,int size) { ListAdapter list_adapter = listView.getAdapter(); ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); int UNBOUNDED = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int grossElementHeight = 0; for (int g = 0; g <size; g++) { View childView = list_adapter.getView(g, null, listView); childView.measure(UNBOUNDED, UNBOUNDED); grossElementHeight += childView.getMeasuredHeight(); } layoutParams.height = grossElementHeight; listView.setLayoutParams(layoutParams); listView.invalidate(); }
No comments:
Post a Comment