Skip to content

Commit

Permalink
上拉加载更多条目限制
Browse files Browse the repository at this point in the history
  • Loading branch information
zjlong committed May 9, 2016
1 parent 5b0c9f1 commit ec83ba6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 303 deletions.
121 changes: 121 additions & 0 deletions app/src/main/java/com/matto/ui/activity/AutoLoadMoreListView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.matto.ui.activity;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;

import com.matto.R;

/**
* @ClassName: XListView.java
* @author: 蜡笔小新
* @date: 2016-04-28 17:53
*/
public class AutoLoadMoreListView extends ListView implements AbsListView.OnScrollListener {

int mFirstVisibleItem; //当前第一个可见Item的位置
int mTotalItemCount;
int mLastVisibleItem; //最后一个可见Item的位置
boolean isMarkItem; // 标记第一个出现的Item

int mScrollState; // 滚动状态
int state; //当前状态

final int NONE = 0; // 正常状态
final int PULL = 1; // 下拉刷新状态
final int RELESE = 2; // 松开释放状态

boolean isLoading; //正在加载
private View mFooterView;
private ILoadMoreCallback mCallback;
private int startY;

public AutoLoadMoreListView(Context context) {
super(context);
initView(context);
}

public AutoLoadMoreListView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}

public AutoLoadMoreListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}

private void initView(Context context) {
LayoutInflater inflater = LayoutInflater.from(context);
mFooterView = inflater.inflate(R.layout.view_footer_layout, null);
mFooterView.setVisibility(GONE);

// 设置滚动监听
setOnScrollListener(this);
// 去掉底部分割线
setFooterDividersEnabled(false);
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mFirstVisibleItem = firstVisibleItem;
mTotalItemCount = totalItemCount;
mLastVisibleItem = firstVisibleItem + visibleItemCount;
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
mScrollState = scrollState;
if (mTotalItemCount == mLastVisibleItem && mScrollState == SCROLL_STATE_IDLE) {
if (!isLoading) {
isLoading = true;
mFooterView.setVisibility(VISIBLE);
mCallback.onLoadMore();
}
}
}


@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mFirstVisibleItem == 0) {
isMarkItem = true;
startY = (int) ev.getY();
}
break;

case MotionEvent.ACTION_MOVE:
onMove(ev);
break;
case MotionEvent.ACTION_UP:

break;
}
return super.onTouchEvent(ev);
}


/*
* 判断移动过程中的操作
*/
private void onMove(MotionEvent e) {

}


public void setOnLoadMoreListener(ILoadMoreCallback callback) {
mCallback = callback;
}

public interface ILoadMoreCallback {
void onRefresh();

void onLoadMore();
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/view_footer_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

</ProgressBar>
11 changes: 5 additions & 6 deletions basic/src/main/java/com/common/model/control/GlideProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public class GlideProxy {

public static final String ANDROID_RESOURCE = "android.resource://";
public static final String FOREWARD_SLASH = "/";

private static GlideProxy instance;
private GlideProxy() {}

private static class GlideControlHolder {
private static GlideProxy instance = new GlideProxy();
}

public static GlideProxy getInstance() {
return GlideControlHolder.instance;
if (instance ==null){
instance = new GlideProxy();
}
return instance;
}

// 将资源ID转为Uri
Expand Down
3 changes: 2 additions & 1 deletion basic/src/main/java/com/common/model/control/LogicProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import java.util.Map;

/**
* Created by snower on 16-1-13.
* author meikoz on 2016/4/13.
* email [email protected]
*/
public class LogicProxy {
private static final LogicProxy m_instance = new LogicProxy();
Expand Down
Loading

0 comments on commit ec83ba6

Please sign in to comment.