From 1e14ee07ef778a3804c4a555c3d16d29eb2b5c0f Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 20 Feb 2024 04:54:07 +0100 Subject: [PATCH] Measure height in the presence of width --- src/main/java/de/monocles/chat/Util.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/monocles/chat/Util.java b/src/main/java/de/monocles/chat/Util.java index 8d9dcd2d0..7b7cc486a 100644 --- a/src/main/java/de/monocles/chat/Util.java +++ b/src/main/java/de/monocles/chat/Util.java @@ -17,9 +17,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 = View.MeasureSpec.makeMeasureSpec(width, View.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(); }