Search in sources :

Example 1 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project baseAdapter by hongyangAndroid.

the class RecyclerViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recyclerview);
    initDatas();
    mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
    //        mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    //        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
    mAdapter = new CommonAdapter<String>(this, R.layout.item_list, mDatas) {

        @Override
        protected void convert(ViewHolder holder, String s, int position) {
            holder.setText(R.id.id_item_list_title, s + " : " + holder.getAdapterPosition() + " , " + holder.getLayoutPosition());
        }
    };
    initHeaderAndFooter();
    //        initEmptyView();
    mLoadMoreWrapper = new LoadMoreWrapper(mHeaderAndFooterWrapper);
    mLoadMoreWrapper.setLoadMoreView(R.layout.default_loading);
    mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    for (int i = 0; i < 10; i++) {
                        mDatas.add("Add:" + i);
                    }
                    mLoadMoreWrapper.notifyDataSetChanged();
                }
            }, 3000);
        }
    });
    mRecyclerView.setAdapter(mLoadMoreWrapper);
    mAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
            Toast.makeText(RecyclerViewActivity.this, "pos = " + position, Toast.LENGTH_SHORT).show();
            mAdapter.notifyItemRemoved(position);
        }

        @Override
        public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
            return false;
        }
    });
}
Also used : LoadMoreWrapper(com.zhy.adapter.recyclerview.wrapper.LoadMoreWrapper) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CommonAdapter(com.zhy.adapter.recyclerview.CommonAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ViewHolder(com.zhy.adapter.recyclerview.base.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class BookCustomFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    showContentView();
    bindingView.srlBook.setColorSchemeColors(CommonUtils.getColor(R.color.colorTheme));
    bindingView.srlBook.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            DebugUtil.error("-----onRefresh");
            //                listTag= Arrays.asList(BookApiUtils.getApiTag(position));
            //                String tag=BookApiUtils.getRandomTAG(listTag);
            //                doubanBookPresenter.searchBookByTag(BookReadingFragment.this,tag,false);
            bindingView.srlBook.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mStart = 0;
                    loadCustomData();
                }
            }, 1000);
        }
    });
    //        mBookAdapter = new BookAdapter(getActivity());
    //        mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    mLayoutManager = new GridLayoutManager(getActivity(), 3);
    bindingView.xrvBook.setLayoutManager(mLayoutManager);
    //        bindingView.xrvBook.setAdapter(mBookAdapter);
    scrollRecycleView();
    // 准备就绪
    mIsPrepared = true;
    /**
         * 因为启动时先走loadData()再走onActivityCreated,
         * 所以此处要额外调用load(),不然最初不会加载内容
         */
    loadData();
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.

the class WelfareFragment method setAdapter.

private void setAdapter(GankIoDataBean gankIoDataBean) {
    //        mWelfareAdapter = new WelfareAdapter();
    mWelfareAdapter.addAll(gankIoDataBean.getResults());
    //构造器中,第一个参数表示列数或者行数,第二个参数表示滑动方向,瀑布流
    bindingView.xrvWelfare.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    bindingView.xrvWelfare.setAdapter(mWelfareAdapter);
    mWelfareAdapter.notifyDataSetChanged();
    mWelfareAdapter.setOnItemClickListener(new OnItemClickListener<GankIoDataBean.ResultBean>() {

        @Override
        public void onClick(GankIoDataBean.ResultBean resultsBean, int position) {
            DebugUtil.error("-----" + imgList.toString());
            DebugUtil.error("----imgList.size():  " + imgList.size());
            Bundle bundle = new Bundle();
            // 2,大图显示当前页数,1,头像,不显示页数
            bundle.putInt("selet", 2);
            //第几张
            bundle.putInt("code", position);
            bundle.putStringArrayList("imageuri", imgList);
            Intent intent = new Intent(getContext(), ViewBigImageActivity.class);
            intent.putExtras(bundle);
            getContext().startActivity(intent);
        }
    });
    // 显示成功后就不是第一次了,不再刷新
    isFirst = false;
}
Also used : GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) Bundle(android.os.Bundle) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) Intent(android.content.Intent) ViewBigImageActivity(com.example.jingbin.cloudreader.view.viewbigimage.ViewBigImageActivity)

Example 4 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project EasyRecyclerView by Jude95.

the class DividerDecoration method onDrawOver.

public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }
    int orientation = 0;
    int headerCount = 0, footerCount = 0, dataCount;
    if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
        headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
        footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
        dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
    } else {
        dataCount = parent.getAdapter().getItemCount();
    }
    int dataStartPosition = headerCount;
    int dataEndPosition = headerCount + dataCount;
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof GridLayoutManager) {
        orientation = ((GridLayoutManager) layoutManager).getOrientation();
    } else if (layoutManager instanceof LinearLayoutManager) {
        orientation = ((LinearLayoutManager) layoutManager).getOrientation();
    }
    int start, end;
    if (orientation == OrientationHelper.VERTICAL) {
        start = parent.getPaddingLeft() + mPaddingLeft;
        end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
    } else {
        start = parent.getPaddingTop() + mPaddingLeft;
        end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
    }
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(child);
        if (//数据项除了最后一项
        position >= dataStartPosition && position < dataEndPosition - 1 || //数据项最后一项
        (position == dataEndPosition - 1 && mDrawLastItem) || //header&footer且可绘制
        (!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
            if (orientation == OrientationHelper.VERTICAL) {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int top = child.getBottom() + params.bottomMargin;
                int bottom = top + mHeight;
                mColorDrawable.setBounds(start, top, end, bottom);
                mColorDrawable.draw(c);
            } else {
                RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
                int left = child.getRight() + params.rightMargin;
                int right = left + mHeight;
                mColorDrawable.setBounds(left, start, right, end);
                mColorDrawable.draw(c);
            }
        }
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerArrayAdapter(com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 5 with StaggeredGridLayoutManager

use of android.support.v7.widget.StaggeredGridLayoutManager in project BaseRecyclerViewAdapterHelper by CymChad.

the class BaseQuickAdapter method disableLoadMoreIfNotFullPage.

/**
     * check if full page after {@link #setNewData(List)}, if full, it will enable load more again.
     *
     * @param recyclerView your recyclerView
     * @see #setNewData(List)
     */
public void disableLoadMoreIfNotFullPage(RecyclerView recyclerView) {
    if (recyclerView == null)
        return;
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager == null)
        return;
    if (manager instanceof LinearLayoutManager) {
        final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) manager;
        recyclerView.postDelayed(new Runnable() {

            @Override
            public void run() {
                if ((linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1) != getItemCount()) {
                    setEnableLoadMore(true);
                }
            }
        }, 50);
    } else if (manager instanceof StaggeredGridLayoutManager) {
        final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) manager;
        recyclerView.postDelayed(new Runnable() {

            @Override
            public void run() {
                final int[] positions = new int[staggeredGridLayoutManager.getSpanCount()];
                staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(positions);
                int pos = getTheBiggestNumber(positions) + 1;
                if (pos != getItemCount()) {
                    setEnableLoadMore(true);
                }
            }
        }, 50);
    }
}
Also used : 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)64 View (android.view.View)50 GridLayoutManager (android.support.v7.widget.GridLayoutManager)37 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)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 Point (android.graphics.Point)7 ViewGroup (android.view.ViewGroup)6 WebView (android.webkit.WebView)6 ScrollView (android.widget.ScrollView)6 SuppressLint (android.annotation.SuppressLint)5 List (java.util.List)5