1. Look at the effect picture first

Note: Ignore the title bar top suction effect for now. If you want to know the sliding top suction effect, you can go to my home page to view other articles (cool top suction effect).

A. First of all, the whole layout is a ByRecyclerView

B. RecyclerView to achieve multiple layout

C. The rotation diagram and classification button at the top is the first item of ByRecyclerView

D. Below is the actual list data

@override public int getItemViewType(int position) {if (position == 0) {
            return ITEM_TYPE_1;
        } else {
            returnITEM_TYPE_2; } } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { RecyclerView.ViewHolder holder = null; // If the item type is equal to 1, load the wheel map, otherwise load the list of articlesif (i == ITEM_TYPE_1) {
            View viewTop = LayoutInflater.from(activity).inflate(R.layout.home_tab,  viewGroup, false);
            if(holder == null) { holder = new BannnerViewHolder(viewTop); }}else if (i == ITEM_TYPE_2) {
            View view = LayoutInflater.from(activity).inflate(R.layout.item_layout_like1, viewGroup, false); // View View = layoutinflater.from (activity).inflate(r.layout.item_layout_like1, null);if(holder == null) { holder = new ArticleViewHolder(view); }}return holder;
    }

Copy the code

3. Add adapters for ByRecyclerView

As you can see, recyclerView is set to 2 columns

GridLayoutManager manager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(manager);
homeLikeAdapter = new HomeAdapter3(activity);
homeLikeAdapter.setHasStableIds(true);
recyclerView.setAdapter(homeLikeAdapter);
Copy the code

Position =0, position=0, position=0, position=0

/ * * * to solve recyclerview layout, dynamic control the number of columns * 1 column, is the first item is behind the 2 columns * / manager. SetSpanSizeLookup (new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int spanSize;
                if(homeLikeAdapter.getItemViewType(position) == HomeAdapter1.ITEM_TYPE_1) { spanSize = 2; // cross 2 columns}else if(homeLikeAdapter.getItemViewType(position) == HomeAdapter1.ITEM_TYPE_2) { spanSize = 1; // cross 1 column}else {
                    spanSize = 2;
                }
                returnspanSize; }});Copy the code

In order to keep the length of a single article simple, I will write each question separately