1、整理项目中遇到的ListView使用方法:
import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.ListView; public class InnerListView extends ListView { private int maxHeight; public int getMaxHeight() { return maxHeight; } public void setMaxHeight(int maxHeight) { this.maxHeight = maxHeight; } public InnerListView(Context context) { super(context); } public InnerListView(Context context, AttributeSet attributeSet) { super(context, attributeSet); } public InnerListView(Context context, AttributeSet attributeSet, int defStyle) { super(context, attributeSet, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub // if (maxHeight > -1) { // heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST); // } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: //当手指触到listview的时候,让父ScrollView交出ontouch权限,也就是让父scrollview setParentScrallAble(false); break; case MotionEvent.ACTION_UP: ////当手指松开时,让父ScrollView重新拿到onTouch权限 setParentScrallAble(true); break; default: break; } return super.onInterceptTouchEvent(ev); } private void setParentScrallAble(boolean flag) { // TODO Auto-generated method stub getParent().requestDisallowInterceptTouchEvent(!flag); } }
层参考网络文档,具体链接已经记不清了