Android的 - OnScrollListener的交错网格视图 [英] Android - OnScrollListener for Staggered Grid View

查看:202
本文介绍了Android的 - OnScrollListener的交错网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅我的英语,我是法国人......

Please excuse my English, I'm French...

所以,我有我的Andr​​oid应用程序的问题。 我已经整合网格视图Pinterest的风格。 我发现这个LIB:交错网格视图( https://github.com/maurycyw/StaggeredGridView

So, I've got a question for my Android App. I've to integrate a grid view as Pinterest style. I found this lib : Staggered Grid View (https://github.com/maurycyw/StaggeredGridView)

这是工作的罚款,但......有没有OnScrollListener! 我必须知道,当用户看到的最后一个项目,以装载更多。 但它不可能没有OnScrollListener!

It's work fine but... There is no OnScrollListener ! I had to know when the user see the last item, in order to load more. But it's not possible without OnScrollListener !

你有一个想法,我的问题?

Have you got an idea for my problem ?

多谢了。

推荐答案

更新:
经过测试,
呼叫 notifyDataSetChanged() StaggeredGridView适配器情况下重置滚动位置为0(启动观)。
而是使用 PinterestLikeAdapterView

UPDATE:
After testing,
Calling notifyDataSetChanged() for StaggeredGridView Adapter case to reset the scroll position to 0 (Start of the Views).
Instead use PinterestLikeAdapterView

我有加 loadMoreListener StaggeredGridView
步骤:
1-添加loadmore接口和booelan isLoading(在类的顶部)

I have add loadMoreListener to the StaggeredGridView
steps:
1- add a loadmore Interface and booelan isLoading (at the top of the class)

public interface OnLoadMoreListener {
    public boolean onLoadMore();
}

private boolean mIsLoading;
private OnLoadMoreListener mLoadMoreListener;

2 - 查找 trackMotionScroll 功能,的其他移动deltaY> 0
和之后的起来= FALSE; 添加

2- find trackMotionScroll function, in the else of deltaY > 0
and after the up = false; add

if (overhang <= 80) { // 80 is how nearest to the end. ZERO mean the end of list
    // scrolling down and almost reach the end of list
    if (false == mIsLoading && null != mLoadMoreListener) {
        if (false == mLoadMoreListener.onLoadMore()) {
            mIsLoading = true;
            Log.d(TAG, "loadMore");
        }
    }
}

3添加使用setListener() loadComplated()功能

public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) {
    this.mLoadMoreListener = onLoadMoreListener;
}

public void loadMoreCompleated() {
    mIsLoading = false;
}

如何使用
1 - 定义一个 loadMoreListener 活动/片段

HOW to use:
1- define a loadMoreListener in your Activity/Fragment

private StaggeredGridView.OnLoadMoreListener loadMoreListener = new StaggeredGridView.OnLoadMoreListener() {

    @Override
    public boolean onLoadMore() {
        loading.setVisibility(View.VISIBLE);
        // load more data from internet (not in the UI thread)

        return true; // true if you have more data to load, false you dont have more data to load 
    }
};

2 - 当你做数据加载,并将其添加到适配器通话

2- when you done data loading and add it to the adapter call

private void doneLoading() {
    gridView.loadMoreCompleated();
    loading.setVisibility(View.GONE);
}

这篇关于Android的 - OnScrollListener的交错网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆