diff options
| author | Philip Milne <pmilne@google.com> | 2011-06-13 10:44:49 -0700 |
|---|---|---|
| committer | Philip Milne <pmilne@google.com> | 2011-06-13 10:44:49 -0700 |
| commit | 51f17d54613c33638c8a2da8affcd9ba35994cb3 (patch) | |
| tree | 06e4240a72a2528dcfe3e21c8a2c4f19bbedcac6 /core/java/android/widget | |
| parent | 60f36a52ac57018d33b284ee5b4f71ba869f54f0 (diff) | |
| download | frameworks_base-51f17d54613c33638c8a2da8affcd9ba35994cb3.zip frameworks_base-51f17d54613c33638c8a2da8affcd9ba35994cb3.tar.gz frameworks_base-51f17d54613c33638c8a2da8affcd9ba35994cb3.tar.bz2 | |
Bugfix for GridLayout assuming that the x value of last column index is maximal. This is not the case when column indexes are defined incorrectly and GridLayout should still work in this case.
Change-Id: I5deb3fb43ed1dd16dd20868854b96ebae4d30623
Diffstat (limited to 'core/java/android/widget')
| -rw-r--r-- | core/java/android/widget/GridLayout.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java index bda82a3..092c2f7 100644 --- a/core/java/android/widget/GridLayout.java +++ b/core/java/android/widget/GridLayout.java @@ -494,6 +494,14 @@ public class GridLayout extends ViewGroup { requestLayout(); } + private static int max2(int[] a, int valueIfEmpty) { + int result = valueIfEmpty; + for (int i = 0, N = a.length; i < N; i++) { + result = Math.max(result, a[i]); + } + return result; + } + private static int sum(float[] a) { int result = 0; for (int i = 0, length = a.length; i < length; i++) { @@ -1409,7 +1417,7 @@ public class GridLayout extends ViewGroup { // External entry points private int size(int[] locations) { - return locations[locations.length - 1] - locations[0]; + return max2(locations, 0) - locations[0]; } private int getMin() { @@ -1878,21 +1886,13 @@ public class GridLayout extends ViewGroup { return result; } - private static int max(int[] a, int valueIfEmpty) { - int result = valueIfEmpty; - for (int i = 0, length = a.length; i < length; i++) { - result = Math.max(result, a[i]); - } - return result; - } - /* Create a compact array of keys or values using the supplied index. */ private static <K> K[] compact(K[] a, int[] index) { int size = a.length; Class<?> componentType = a.getClass().getComponentType(); - K[] result = (K[]) Array.newInstance(componentType, max(index, -1) + 1); + K[] result = (K[]) Array.newInstance(componentType, max2(index, -1) + 1); // this overwrite duplicates, retaining the last equivalent entry for (int i = 0; i < size; i++) { |
