I have list view inside scroll view and do calculation height base of children. Here is code I use :
public static void SetListViewHeightBasedOnChildren (ListView listView)
{
IListAdapter listAdapter = listView.Adapter;
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = listView.PaddingTop + listView.PaddingBottom;
for (int i = 0; i < listAdapter.Count; i++) {
View listItem = listAdapter.GetView (i, null, listView);
listItem.LayoutParameters = new Android.Views.ViewGroup.LayoutParams (
ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
listItem.Measure (0, 0);
totalHeight += listItem.MeasuredHeight;
}
ViewGroup.LayoutParams params_ = listView.LayoutParameters;
params_.Height = totalHeight + (listView.DividerHeight * listAdapter.Count) + 50;
listView.LayoutParameters = params_;
listView.RequestLayout ();
}
generally, it works good, but for some cases ( if listview item is too large and e.t) last row it trimmed.
hierarchy in .xml
Scroll view -> RelativeLayout -> LinearLayout->ListView