Java tutorial
//package com.java2s; import android.util.Log; import android.view.ViewGroup; import android.widget.ListAdapter; import android.widget.ListView; public class Main { public static void getListViewSize2(ListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) { //do nothing return null return; } //set listAdapter in loop for getting final size int totalHeight = 70; for (int size = 0; size <= myListAdapter.getCount() + 1; size++) { totalHeight += 70; } totalHeight += 140; ViewGroup.LayoutParams params = myListView.getLayoutParams(); params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() + 2)); myListView.setLayoutParams(params); Log.i("height of listItem:", String.valueOf(totalHeight)); } }