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只能有一个子类

  • 相关阅读:
    TCL 双引号和花括号的区别
    在Vivado中调用ModelSim生成FSM的状态转移图
    基于配置文件的方式来配置AOP
    Spring MVC_Hello World
    重用切点表达式
    Spring MVC概述(2)
    Shiro_DelegatingFilterProxy
    Shiro-工作流程
    切面的优先级
    Shiro-集成Spring
  • 原文地址:https://www.cnblogs.com/jsonfan/p/5388858.html
Copyright © 2011-2022 走看看