There is a twoway-view library that allows you to create a custom recycler view as I need

https://github.com/lucasr/twoway-view

Just do not understand how to import it correctly

According to the description you need to do like this

 compile 'org.lucasr.twowayview:twowayview:0.1.4' 

But immediately there are problems when you make this custom recycler view in the markup

 <org.lucasr.twowayview.widget.TwoWayView android:id="@+id/rvMain" android:layout_width="match_parent" android:layout_height="match_parent" app:twowayview_layoutManager="StaggeredGridLayoutManager" app:twowayview_numColumns="2" app:twowayview_numRows="2" /> 

The namespace is defined, but there are no property names, so I had to manually find all attrs.xml in the repository of this library and add them to myself (as for me it’s not very convenient for a lib with 4500 stars rating)

Well, ok, then I started working with the adapter and created my own based on the example, but my project does not see imports

 import com.fittingroom.newtimezone.view.activityMainNew.recyclerViewUtil.twowayview.TwoWayLayoutManager; import org.lucasr.twowayview.TwoWayLayoutManager; import org.lucasr.twowayview.widget.SpannableGridLayoutManager; import org.lucasr.twowayview.widget.StaggeredGridLayoutManager; import org.lucasr.twowayview.widget.TwoWayView; 

I don’t know what a snapshot is (it’s written in Google that it’s a snapshot of the project’s status), but I don’t understand what it means in the description of this lib, but I tried to import it into my project

 repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { compile 'org.lucasr.twowayview:core:1.0.0-SNAPSHOT@aar' compile 'org.lucasr.twowayview:layouts:1.0.0-SNAPSHOT@aar' } 

and then the project showed me that I try to import this lib more than once

In general, I do not understand how this should work? Who worked with this lib tell me the secret?

Or can you recommend another approach? I generally need to do this recycler view

enter image description here

I already did CardView, I need to figure out now how to make such a template as in the picture for my recycler view

  • And if you just try it like this? compile 'org.lucasr.twowayview:twowayview:0.1.4' - Yuriy SPb
  • snepshot is intermediate (test) assembly, no one vouchs for their performance. The manual has two options for connecting: a snapshot from a separate maven repository or a stable version from jCenter. You only need to choose one of the options. - pavlofff
  • @Yuriy SPb, so I also wrote about this in the question) that if I just add a dependency, I don’t see any imports in the adapter ... Try adding the dependency to an empty project and copy the adapter from the example and put it in your project - Aleksey Timoshchenko
  • @pavlofff yes, but when I choose a stable version, I don’t see any imports in the adapter ... Try adding the dependency to an empty project and copying the adapter from the example and putting it into your project - Aleksey Timoshchenko
  • Try version 0.1.3 - it is the latest in releases - YuriySPb

1 answer 1

As a result, all the magic here in these lines

 StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams(); layoutParams.setFullSpan(true); 

This is what my adapter looks like.

 public class AdapterRecViewMain extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<BaseMarkerElement> mainCardList; private final int HEADER_VIEW = 0; private final int FOOTER_VIEW = 1; public AdapterRecViewMain() { } public void setData(List<BaseMarkerElement> mainCardList) { this.mainCardList = mainCardList; } @Override public int getItemViewType(int position) { if (position == 0) { return HEADER_VIEW; } return FOOTER_VIEW; } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) { if (type == FOOTER_VIEW) { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.card_main_activity, viewGroup, false); return new MainCardViewHolder(v); } else { View v = LayoutInflater.from(viewGroup.getContext()) .inflate(R.layout.header_view_main_activity, viewGroup, false); return new HeaderViewHolder(v); } } @Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int positionItem) { final int position = viewHolder.getAdapterPosition(); if (viewHolder instanceof HeaderViewHolder) { StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) viewHolder.itemView.getLayoutParams(); layoutParams.setFullSpan(true); BaseMarkerElement item = mainCardList.get(position); if (item instanceof HeaderView) { HeaderView header = (HeaderView) mainCardList.get(position); // need to add implementation } } else if (viewHolder instanceof MainCardViewHolder) { MainCardViewHolder currentView = (MainCardViewHolder) viewHolder; CardMainActivity currentCard = (CardMainActivity) mainCardList.get(position); currentView.ivMainCard.setImageResource(currentCard.getIvMainCard()); currentView.tvBrandName.setText(currentCard.getTvBrandName()); currentView.tvPrice.setText(currentCard.getTvPrice()); currentView.tvType.setText(currentCard.getTvType()); } } @Override public int getItemCount() { return mainCardList.size(); } private class MainCardViewHolder extends RecyclerView.ViewHolder { ImageView ivMainCard; TextView tvBrandName; TextView tvType; TextView tvPrice; MainCardViewHolder(View view) { super(view); ivMainCard = (ImageView) view.findViewById(R.id.imageViewMainCard); tvBrandName = (TextView) view.findViewById(R.id.tvBrandName); tvType = (TextView) view.findViewById(R.id.tvType); tvPrice = (TextView) view.findViewById(R.id.tvPrice); } } private class HeaderViewHolder extends RecyclerView.ViewHolder { public HeaderViewHolder(View itemView) { super(itemView); } } } 

the result is the same as in the picture in my question