任何想法如何使用兩個不同的LayoutManager
在一個視圖?我在屏幕和底部的頂格四張牌,我想LinearLayout
但RecyclerView
一次顯示GridLayout和LinearLayout都在一個RecyclerView中
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(mLayoutManager);
RecyclerView.LayoutManager lmLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(lmLayoutManager);
recyclerView.addItemDecoration(new GridSpacingDashboard(2, dpToPx(2), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
一種觀點有什麼辦法,我可以在一個單一的RecyclerView
或者對指數OI使用這兩種瀏覽有GridLayout
和1顯示LinearLayout
,如何才能實現,如果有任何可能性
更新(卡適配器)
public class CardAdapter extends RecyclerView.Adapter<adapter.CardAdapter.CardViewHolder> {
public static final int topGridCard = 0;
public static final int bottomCards=1;
private Context mContext;
private List<CardModel> cardList;
public CardAdapter(Context mContext, List<CardModel> cardList) {
this.mContext = mContext;
this.cardList = cardList;
}
@Override
public.adapter.CardAdapter.CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v;
if (viewType == topGridCard) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_sec, parent, false);
return new adapter.CardAdapter.TopGridCardView(v);
}
else if (viewType == bottomCards) {
v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent, false);
return new adapter.CardAdapter.BottomCardView(v);
}
return null;
}
@Override
public void onBindViewHolder(final adapter.CardAdapter.CardViewHolder holder, final int position) {
CardModel cardModel = cardList.get(position);
if (holder.getItemViewType()==topGridCard){ adapter.CardAdapter.TopGridCardView vholder = (adapter.CardAdapter.TopGridCardView) holder;
vholder.secTitleStats.setText(cardModel.getNumStats());
vholder.secNumStats.setText(cardModel.getCardTitles());
vholder.secCardStats.setText(cardModel.getSecCartNumStats());
Glide.with(mContext).load(cardModel.getThumbnail()).into(vholder.secthumbnail);
}
else if(holder.getItemViewType()==bottomCards){
adapter.CardAdapter.BottomCardView vholder = (adapter.CardAdapter.BottomCardView) holder;
vholder.numStats.setText(cardModel.getNumStats());
vholder.image_title.setText(cardModel.getCardTitles());
Glide.with(mContext).load(cardModel.getThumbnail()).into(vholder.thumbnail);
}
}
@Override
public int getItemCount(){
return cardList.size();
}
public static class CardViewHolder extends RecyclerView.ViewHolder {
public CardViewHolder(View v) {
super(v);
}
}
public class TopGridCardView extends adapter.CardAdapter.CardViewHolder {
public TextView secTitleStats, secNumStats,secCardStats;
public ImageView secthumbnail;
public TopGridCardView(View view){
super(view);
secTitleStats = (TextView) view.findViewById(R.id.secTitleNumStats);
secNumStats = (TextView) view.findViewById(R.id.secCardNumStats);
secCardStats = (TextView) view.findViewById(R.id.sectitle);
secthumbnail = (ImageView) view.findViewById(R.id.seCthumbnail);
}
}
public class BottomCardView extends adapter.CardAdapter.CardViewHolder {
public TextView numStats,image_title;
public ImageView thumbnail;
public BottomCardView(View view) {
super(view);
numStats=(TextView)view.findViewById(R.id.numStatics);
image_title=(TextView) view.findViewById(R.id.title_overlay);
thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
}
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position))
return topGridCard;
return bottomCards;
}
private boolean isPositionHeader(int position) {
return position == 0;
}
}
我已經在我的連接適配器只是爲了更站立,期望的結果應該是什麼 | Grid Card 1 | Grid Card 2 | | Grid Card 3 | Grid Card 4 | | LinearLayout卡1 | | LinearLayout卡2 |
任何可能性
您可以使用此庫[鏈接](https://github.com/j2esu/rv-joiner)或嘗試**回收視圖**多視圖類型 –
無需爲您的功能使用LinearLayout。 GridLayoutManager可以像線性和網格一樣處理。檢查出鏈接:http://stackoverflow.com/questions/30808225/dynamically-change-the-number-of-columns-of-a-gridlayoutmanager –
我有更新我的問題,你可以請關於它的建議,雖然只使用GridLayout經理它只顯示網格卡,但不LinearLayout卡 – Mohtashim