I have a complex xml file and I really need a ScrollView. Please Don\'t mind the Ids as I have changed them. The ScrollView here doesn\'t work.
You can set it by engulfing ListView in a parent layout like an example below -
And, after the listview is populated -
eachitemSize = 180;
cardBrand.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, eachitemSize * brandsAdapter.getCount()));
cardRating.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, eachitemSize * ratingAdapter.getCount()));
What we did above is, we set the ScrollView height to match_parent. And after the ListView is populated we defined each parent layout of ListView to its ListView item count. And, remember to change the value of eachitemSize according to your each cell size.
Another thing to care about is after the LayoutParams is assigned its margin becomes invalid due to the new LayoutParams. So, use instead of margin like the example above.
Hope it helps!!