重写ListView解决item高度不一致的问题
01 | public class MyListView extends ListView { |
02 |
03 | public MyListView(Context context) { |
04 | super (context); |
05 | } |
06 |
07 | public MyListView(Context context, AttributeSet attrs) { |
08 | super (context, attrs); |
09 | } |
10 |
11 | public MyListView(Context context, AttributeSet attrs, |
12 | int defStyle) { |
13 | super (context, attrs, defStyle); |
14 | } |
15 |
16 | @Override |
17 | protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec) {//主要是这个方法 |
18 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2 , |
19 | MeasureSpec.AT_MOST); |
20 | super .onMeasure(widthMeasureSpec, expandSpec); |
21 | } |
22 |
23 | } |