List of usage examples for android.widget ProgressBar getMeasuredHeight
public final int getMeasuredHeight()
From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java
/** * */*from ww w .j a v a 2s.co m*/ * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView percentage = (TextView) view.findViewById(R.id.percentage); ProgressBar progressBar1 = (ProgressBar) view.findViewById(R.id.progressBar1); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += (file.getMeasuredHeight() * numOfLines) + percentage.getMeasuredHeight() + progressBar1.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }