How to Change Listview Height Dynamically in Android

How to change ListView height dynamically in Android?

for change height and width dynamically so, try this

RelativeLayout.LayoutParams mParam = new RelativeLayout.LayoutParams((int)(width),(int)(height);
listView.setLayoutParams(mParam);

you can also use LayoutParams.FILL_PARENT or LayoutParams.WRAP_CONTENT instead of height & width

Set ListView Height dynamically based on multiline textview inside it

As Teemu mentions you need to constrain the width. Sample code below.

float px = 300 * (listView.getResources().getDisplayMetrics().density);
item.measure(View.MeasureSpec.makeMeasureSpec((int)px, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));

Change Height of a Listview dynamicallyAndroid

If you want to change the height of list view dynamically, you could use,

list.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, theSizeIWant));


Related Topics



Leave a reply



Submit