zoukankan      html  css  js  c++  java
  • ScrollView和listview的冲突问题,关于宽度,和滑动

    只需要重新listview即可

    package com.exmple.listscrow;
    
    import java.util.logging.LogManager;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.ListView;
    
    public class MyListView extends ListView {
    
    	int mLastMotionY;
    	boolean bottomFlag;
    
    	public MyListView(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    		// 对height重新赋值
    		heightMeasureSpec = MeasureSpec.makeMeasureSpec(
    		/* Integer.MAX_VALUE>> 2 */300, MeasureSpec.AT_MOST);
    		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    	}
    
    	@Override
    	public boolean onInterceptTouchEvent(MotionEvent ev) {
    		if (bottomFlag) {
    			getParent().requestDisallowInterceptTouchEvent(true);
    		}
    		return super.onInterceptTouchEvent(ev);
    	}
    
    	@Override
    	public boolean onTouchEvent(MotionEvent ev) {
    		int y = (int) ev.getRawY();
    		switch (ev.getAction()) {
    		case MotionEvent.ACTION_DOWN:
    			// 妫f牕鍘涢幏锔藉焻down娴滃�娆�,鐠佹澘缍峺閸ф劖鐖�
    			mLastMotionY = y;
    			break;
    		case MotionEvent.ACTION_MOVE:
    			// deltaY > 0 閺勵垰鎮滄稉瀣�箥閸旓拷,< 0閺勵垰鎮滄稉濠呯箥閸旓拷
    			int deltaY = y - mLastMotionY;
    			if (deltaY < 0) {
    				View child = getChildAt(0);
    				if (child != null) {
    					if (getLastVisiblePosition() == (getChildCount() - 1)
    							
    							) {
    						bottomFlag = true;
    						getParent().requestDisallowInterceptTouchEvent(true);
    					}
    
    					
    				}
    			}
    			break;
    		case MotionEvent.ACTION_UP:
    		case MotionEvent.ACTION_CANCEL:
    			break;
    		}
    		return super.onTouchEvent(ev);
    	}
    
    
    }
    

      注意:ScrollView只能有一个子类

  • 相关阅读:
    linux命令(一)
    Maven 打包不同环境
    Spring动态代理
    Spring MVC controller方法和jstl
    logback的使用
    从文本导入导出
    将临时全局表中的符合字段导入test数据库中
    将上传的新表导入临时全局表中
    建立临时表导入
    查询统计表以及删除表
  • 原文地址:https://www.cnblogs.com/jsonfan/p/5388858.html
Copyright © 2011-2022 走看看