OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.payments.ui; | 5 package org.chromium.chrome.browser.payments.ui; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.util.AttributeSet; | 8 import android.util.AttributeSet; |
| 9 import android.view.View; |
9 import android.widget.GridView; | 10 import android.widget.GridView; |
10 | 11 |
11 /** | 12 /** |
12 * This class is a customized GridView which draws items in multiple lines autom
atically. | 13 * This class is a customized GridView which draws items in multiple lines autom
atically. |
13 */ | 14 */ |
14 public class ExpandableGridView extends GridView { | 15 public class ExpandableGridView extends GridView { |
15 /** Constructor for when the gridview is inflated from XML. */ | 16 /** Constructor for when the gridview is inflated from XML. */ |
16 public ExpandableGridView(Context context, AttributeSet attrs) { | 17 public ExpandableGridView(Context context, AttributeSet attrs) { |
17 super(context, attrs); | 18 super(context, attrs); |
18 } | 19 } |
19 | 20 |
20 @Override | 21 @Override |
21 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 22 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
22 // GridView does not work well in a ScrollView when it uses WRAP_CONTENT
. | 23 // GridView does not work well in a ScrollView when it uses WRAP_CONTENT
. |
23 // Instead, force it to use AT_MOST. | 24 // Instead, force it to use AT_MOST. |
24 // https://stackoverflow.com/questions/4523609/grid-of-images-inside-scr
ollview | 25 // https://stackoverflow.com/questions/4523609/grid-of-images-inside-scr
ollview |
25 final int heightSize = MeasureSpec.getSize(heightMeasureSpec); | |
26 int heightSpec; | 26 int heightSpec; |
27 if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { | 27 if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { |
28 heightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.AT_
MOST); | 28 heightSpec = MeasureSpec.makeMeasureSpec( |
| 29 Integer.MAX_VALUE & View.MEASURED_SIZE_MASK, MeasureSpec.AT_
MOST); |
29 } else { | 30 } else { |
30 heightSpec = heightMeasureSpec; | 31 heightSpec = heightMeasureSpec; |
31 } | 32 } |
32 | 33 |
33 super.onMeasure(widthMeasureSpec, heightSpec); | 34 super.onMeasure(widthMeasureSpec, heightSpec); |
34 } | 35 } |
35 } | 36 } |
OLD | NEW |