This is the issues which has been faced by every android developer.
Below I have shared a class file Which resolve this issue.
Below I have shared a class file Which resolve this issue.
import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.ListAdapter; import com.baoyz.swipemenulistview.SwipeMenuListView; /** * Created by user on 23/12/15. */public class Helper { public static void getListViewSize(SwipeMenuListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return; } //set listAdapter in loop for getting final size int totalHeight = 0; for (int size = 0; size < myListAdapter.getCount(); size++) { View listItem = myListAdapter.getView(size, null, myListView); listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } //setting listview item in adapter ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1)); myListView.setLayoutParams(params); // print height of adapter on log Log.i("height of listItem:", String.valueOf(totalHeight)); } }
OnCreate Method in Activity:-
Helper.getListViewSize(activityList);