OSDN Git Service

Constrain ListPopupWindow hint width spec to >= 0
authorAlan Viverette <alanv@google.com>
Thu, 25 Jun 2015 20:00:03 +0000 (13:00 -0700)
committerAlan Viverette <alanv@google.com>
Thu, 25 Jun 2015 20:00:03 +0000 (13:00 -0700)
Bug: 22092169
Change-Id: Ia05302cf8d167aae26eccbf53dd3fd21d09b326d

core/java/android/widget/ListPopupWindow.java

index 534bfad..c6de5dd 100644 (file)
@@ -1127,10 +1127,19 @@ public class ListPopupWindow {
                     break;
                 }
 
-                // measure the hint's height to find how much more vertical space
-                // we need to add to the drop down's height
-                int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST);
-                int heightSpec = MeasureSpec.UNSPECIFIED;
+                // Measure the hint's height to find how much more vertical
+                // space we need to add to the drop down's height.
+                final int widthSize;
+                final int widthMode;
+                if (mDropDownWidth >= 0) {
+                    widthMode = MeasureSpec.AT_MOST;
+                    widthSize = mDropDownWidth;
+                } else {
+                    widthMode = MeasureSpec.UNSPECIFIED;
+                    widthSize = 0;
+                }
+                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
+                final int heightSpec = MeasureSpec.UNSPECIFIED;
                 hintView.measure(widthSpec, heightSpec);
 
                 hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();