From d9205e7e7b7d1c174010bdedaf812836bd07f2ec Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 19 Feb 2024 22:54:07 -0500 Subject: [PATCH] Measure height in the presence of a width So that wrapping text, etc, is taken in to account --- src/cheogram/java/com/cheogram/android/Util.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cheogram/java/com/cheogram/android/Util.java b/src/cheogram/java/com/cheogram/android/Util.java index 8683a801397b6e0fe63208032410185b642ad65b..1211141f18ae19770e1ef72dcf70b8882178e589 100644 --- a/src/cheogram/java/com/cheogram/android/Util.java +++ b/src/cheogram/java/com/cheogram/android/Util.java @@ -1,6 +1,7 @@ package com.cheogram.android; import android.view.View; +import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.widget.ListView; import android.widget.ListAdapter; @@ -14,9 +15,11 @@ public class Util { } ViewGroup vg = listView; int totalHeight = 0; + final int width = listView.getWidth() > 0 ? listView.getWidth() : listView.getContext().getResources().getDisplayMetrics().widthPixels; + final int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST); for (int i = 0; i < adapter.getCount(); i++) { View listItem = adapter.getView(i, null, vg); - listItem.measure(0, 0); + listItem.measure(widthSpec, 0); totalHeight += listItem.getMeasuredHeight(); }