Scrollviewfresh加载数据 嵌套NonScrollListView,NonScrollListView item中包含NonScrollGridView
这个布局中最外层用的是HeaderViewPager,大概的效果就是京东店铺详情
大致效果是这样,向上滑动,Tablayout能继续选择fragment ,
起初觉得这样嵌套好几层布局会出问题,最后写完,发现并没有问题,重写的Listview
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
重写的Gridview
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
//通过重新dispatchTouchEvent方法来禁止滑动
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
return true;//禁止Gridview进行滑动
}
return super.dispatchTouchEvent(ev);
}
然后就是下拉能加载的Scrollview
public class Scrollviewfresh extends ScrollView {
private OnScrollToBottomListener onScrollToBottom;
public Scrollviewfresh(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public Scrollviewfresh(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public Scrollviewfresh(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,
boolean clampedY) {
// TODO Auto-generated method stub
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
if (scrollY != 0 && null != onScrollToBottom) {
onScrollToBottom.onScrollBottomListener(clampedY);
}
}
public void setOnScrollToBottomLintener(OnScrollToBottomListener listener) {
onScrollToBottom = listener;
}
public interface OnScrollToBottomListener {
public void onScrollBottomListener(boolean isBottom);
}
这个下拉加载的scrollview ,需要再下拉的时候做下判断,
svDisplay.setOnScrollToBottomLintener(new Scrollviewfresh.OnScrollToBottomListener() {
@Override
public void onScrollBottomListener(boolean isBottom) {
isboolean = isBottom + "";
if (isboolean.equals("true") && isOk.equals("false")) {
isOk = "true";
page++;
httpList();
}
}
});
通过两个boolean来做判断,第一个isboolean判断是否滑动到最底部,第二个就是用来判断网络请求是否成功,否则会一直加载网络请求,导致数据重复,
HttpJsonUtil.getShop_New_Goods(shop_id, page + "", 10001, new HttpManager.OnHttpResponseListener() {
@Override
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
if (0 == GetJsonUtil.getResponseCode(resultJson)) {
String json = GetJsonUtil.getResponseData(resultJson);
bindListData(JSON.parseArray(json, ShopNewGoodsBean.class));
if (JSON.parseArray(json, ShopDetailGoodsBean.class).size() == 0) {//没有更多数据了,不能继续加载
isboolean = "false";
isOk = "true";
} else {
isboolean = "false";
isOk = "false";
}
} else {
showShortToast(GetJsonUtil.getResponseError(resultJson));
}
至此,基本上的一个多嵌套布局,加上一个下拉加载已经做完了,具体的填充adapter,就不贴上去了