欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义ListView的写法

程序员文章站 2022-07-15 09:16:10
...

public class MyListView extends ListView {

public MyListView(Context context) {  
    // TODO Auto-generated method stub  
    super(context);  
}  

public MyListView(Context context, AttributeSet attrs) {  
    // TODO Auto-generated method stub  
    super(context, attrs);  
}  

public MyListView(Context context, AttributeSet attrs, int defStyle) {  
    // TODO Auto-generated method stub  
    super(context, attrs, defStyle);  
}  

@Override  
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    // TODO Auto-generated method stub  
    //获取高度
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
            MeasureSpec.AT_MOST);  
    super.onMeasure(widthMeasureSpec, expandSpec);  
}  

}