Search in sources :

Example 81 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class ImageFragment method initData.

@Override
protected void initData() {
    if (!isPrepared || !isVisible || isLoad) {
        return;
    }
    recyclerView.setLoadingData(this);
    recyclerView.setHasFixedSize(true);
    imageListPresenter = new ImagePresenterImpl(this);
    swipeRefreshLayout.setOnRefreshListener(this);
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    adapter = new ImageAdapter(new LinkedList<BaseModel>());
    adapter.setOnItemClickListener(this);
    recyclerView.setAdapter(adapter);
    swipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            onRefresh();
        }
    });
    setLoad();
}
Also used : ImageAdapter(com.jsoupsimple.image.imagelist.widget.adapter.ImageAdapter) ImagePresenterImpl(com.jsoupsimple.image.imagelist.presenter.ImagePresenterImpl) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinkedList(java.util.LinkedList)

Example 82 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class MRecyclerView method onScrolled.

@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);
    RecyclerView.LayoutManager layoutManager = getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 83 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class RecyclerOnScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    switch(layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 84 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project AndroidDevelop by 7449.

the class StaggeredGridLayoutManagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mDatas = new ArrayList<>();
    initData(mDatas);
    adapter = new MyAdapter(mDatas, recyclerView);
    adapter.setLoadingListener(this);
    adapter.setOnItemClickListener(this);
    adapter.addHeader(getView(R.layout.header));
    adapter.addFooter(getView(R.layout.footer));
    recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setAdapter(adapter);
    View headerView = adapter.getHeaderView();
    View footerView = adapter.getFooterView();
    footerView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast("this is footer");
        }
    });
    headerView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast("this is header");
        }
    });
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 85 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project bdcodehelper by boredream.

the class LoadMoreAdapter method setScrollListener.

/**
     * 设置滚动监听, 判断当列表滚动到底部时, 触发加载更多回调
     */
private void setScrollListener() {
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
            if (layoutManager instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
                int pastVisibleItems = -1;
                int visibleItemCount = staggeredGridLayoutManager.getChildCount();
                int totalItemCount = staggeredGridLayoutManager.getItemCount();
                int[] firstVisibleItems = null;
                firstVisibleItems = staggeredGridLayoutManager.findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisibleItems = firstVisibleItems[0];
                }
                if (visibleItemCount + pastVisibleItems >= totalItemCount) {
                    triggerLoadMore();
                }
            } else if (layoutManager instanceof LinearLayoutManager) {
                // GridLayoutManager 是 LinearLayoutManager 的子类, 也符合这个条件
                LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
                int visibleItemCount = linearLayoutManager.getChildCount();
                int totalItemCount = linearLayoutManager.getItemCount();
                int firstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
                if (visibleItemCount + firstVisibleItemPosition >= totalItemCount) {
                    triggerLoadMore();
                }
            }
        }
    });
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)125 RecyclerView (android.support.v7.widget.RecyclerView)76 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)62 View (android.view.View)50 GridLayoutManager (android.support.v7.widget.GridLayoutManager)38 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)11 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 TextView (android.widget.TextView)10 Handler (android.os.Handler)9 BindView (butterknife.BindView)9 Intent (android.content.Intent)8 Nullable (android.support.annotation.Nullable)8 AbsListView (android.widget.AbsListView)8 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 WebView (android.webkit.WebView)6 ScrollView (android.widget.ScrollView)6 List (java.util.List)5 SuppressLint (android.annotation.SuppressLint)4 Point (android.graphics.Point)4