ScorllView 嵌套gridView,listView问题处理

首先GridView去滚动条

package com.ebsig.shop.activitys.util;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class ChangeOfGridView extends GridView{

	public ChangeOfGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public ChangeOfGridView(Context context) {
		// TODO Auto-generated constructor stub
		super(context);
	}
	public ChangeOfGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	
	//去掉滚动
	@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); 

	}
}
ListView需要设置高度
// 设置listView的高度
 private void setListViewHeightBasedOnChildren(ListView listView) {
  ListAdapter listAdapter = listView.getAdapter();
  if (listAdapter == null) {
   return;
  }
  int totalHeight = 0;
  for (int i = 0; i < listAdapter.getCount(); i++) {
   View listItem = listAdapter.getView(i, null, listView);
   listItem.measure(0, 0);
   totalHeight += listItem.getMeasuredHeight();
  }
  ViewGroup.LayoutParams params = listView.getLayoutParams();
  params.height = totalHeight
    + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  ((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
  listView.setLayoutParams(params);
 }
重新下ScorllView

/**  *  */ package com.ebsig.shop.activitys.util;

import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.ScrollView;

/**  * @author tanhuohui  *@Date 2012-12-4  *  */ public class ChangeOfScrollView extends ScrollView {  //滑动的距离和坐标  private float slide_distanceX,slide_distanceY,xLast,yLast;  public ChangeOfScrollView(Context context, AttributeSet attrs) {   super(context, attrs);   // TODO Auto-generated constructor stub  }    @Override  public boolean onInterceptTouchEvent(MotionEvent ev) {   // TODO Auto-generated method stub   switch (ev.getAction()) {         case MotionEvent.ACTION_DOWN:             slide_distanceX = slide_distanceY = 0f;             xLast = ev.getX();             yLast = ev.getY();             break;         case MotionEvent.ACTION_MOVE:             final float curX = ev.getX();             final float curY = ev.getY();                         slide_distanceX += Math.abs(curX - xLast);             slide_distanceY += Math.abs(curY - yLast);             xLast = curX;             yLast = curY;                         if(slide_distanceX > slide_distanceY){              return false;             }      }   return super.onInterceptTouchEvent(ev);  }  

 

}

 

 

 

你可能感兴趣的:(ListView)