Search in sources :

Example 96 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project simple-stack by Zhuinden.

the class KittenGridFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    RecyclerView recyclerView = view.findViewById(R.id.recyclerview);
    recyclerView.setAdapter(new KittenGridAdapter(6));
    recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 97 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project CloudReader by youlookwhat.

the class NavigationContentAdapter method onAttachedToRecyclerView.

@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridManager = ((GridLayoutManager) manager);
        gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                int type = getItemViewType(position);
                /**
                 * 根据GridLayoutManager的getSpanSize方法可以动态的设置item跨列数
                 * 需要设置:4个参数的GridLayoutManager
                 * new GridLayoutManager(getActivity(),6,GridLayoutManager.VERTICAL,false);
                 * 这里的6(自己设置的最好设置成偶数)就相当于分母,6默认显示一整行(1列),下面的3 和2 就相当于分子,返回3就是(1/2)所以此类型对应的是2列,返回2就是(1/3)所以此类型对应的是3列
                 */
                switch(type) {
                    case StickyHeaderHandler.TYPE_STICKY_VIEW:
                        // title栏显示一列
                        return gridManager.getSpanCount();
                    case TYPE_CONTENT:
                        // 内容栏显示2列
                        return 3;
                    default:
                        // 默认显示2列
                        return 3;
                }
            }
        });
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 98 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Transitions-Everywhere by andkulikov.

the class ExplodeAndEpicenterExample method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecyclerView = new RecyclerView(container.getContext());
    mRecyclerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mRecyclerView.setLayoutManager(new GridLayoutManager(container.getContext(), 4));
    mRecyclerView.setAdapter(new Adapter());
    return mRecyclerView;
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ViewGroup(android.view.ViewGroup) RecyclerView(androidx.recyclerview.widget.RecyclerView) TransitionListenerAdapter(androidx.transition.TransitionListenerAdapter) Nullable(androidx.annotation.Nullable)

Example 99 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project UltimateRecyclerView by cymcsg.

the class UltimateRecyclerView method scroll_load_more_detection.

private void scroll_load_more_detection(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else {
            throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    mTotalItemCount = layoutManager.getItemCount();
    mVisibleItemCount = layoutManager.getChildCount();
    switch(layoutManagerType) {
        case LINEAR:
            mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
            lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
            break;
        case GRID:
            if (layoutManager instanceof GridLayoutManager) {
                GridLayoutManager ly = (GridLayoutManager) layoutManager;
                lastVisibleItemPosition = ly.findLastVisibleItemPosition();
                mFirstVisibleItem = ly.findFirstVisibleItemPosition();
            }
            break;
        case STAGGERED_GRID:
            if (layoutManager instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;
                if (mlastPositionsStaggeredGridLayout == null)
                    mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];
                sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);
                sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
            }
            break;
    }
    if (automaticLoadMoreEnabled) {
        if (mTotalItemCount > previousTotal) {
            automaticLoadMoreEnabled = false;
            previousTotal = mTotalItemCount;
        }
    }
    boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;
    if (bottomEdgeHit) {
        if (mIsLoadMoreWidgetEnabled) {
            /**
             *auto activate load more*
             */
            if (!automaticLoadMoreEnabled) {
                onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
                automaticLoadMoreEnabled = true;
            }
        }
        mAdapter.internalExecuteLoadingView();
        previousTotal = mTotalItemCount;
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 100 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project UltimateRecyclerView by cymcsg.

the class catelogGrid method renderviewlayout.

protected void renderviewlayout(View view) throws Exception {
    listview_layout = (UltimateRecyclerView) view.findViewById(getUltimate_recycler_viewResId());
    listview_layout.setHasFixedSize(true);
    listview_layout.setSaveEnabled(true);
    if (mLayoutManager == null) {
        mLayoutManager = new GridLayoutManager(view.getContext(), getColumn(), LinearLayoutManager.VERTICAL, false);
    }
    listview_layout.setLayoutManager(mLayoutManager);
    getProgressbar(view);
    listview_layout.setAdapter(madapter = getAdatperWithdata());
    setUltimateRecyclerViewExtra(listview_layout, madapter);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)109 RecyclerView (androidx.recyclerview.widget.RecyclerView)57 View (android.view.View)44 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)14 ImageView (android.widget.ImageView)11 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)11 Toolbar (androidx.appcompat.widget.Toolbar)10 Nullable (androidx.annotation.Nullable)9 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 ViewGroup (android.view.ViewGroup)6 SuppressLint (android.annotation.SuppressLint)5 Context (android.content.Context)5 NonNull (androidx.annotation.NonNull)5 ArrayList (java.util.ArrayList)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 List (java.util.List)4 Handler (android.os.Handler)3 FrameLayout (android.widget.FrameLayout)3 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)3