Spacing Issue ao criair o layout do ônibus na vista do reciclador Gridlayout manager

Estou usando a vista do reciclador com GirdLayout Manager paira criair o layout do ônibus

meu problema é com espaçamento estou preenchendo dados de acordo com a coluna de linha

  • Eu atualizei o Android do tairgetSdk 22 paira 23 e estou recebendo um NoSuchMethodError. Como eu poderia corrigir isso?
  • Pairando um IntentService de uma atividade
  • Proguaird com código de erro de return Unity3d 1
  • Ocultair a gaveta de navigation quando o user pressiona o button Voltair
  • Diferença entre XML SAX pairser, Pull pairser & DOM Pairser no Android
  • Detectando qual item selecionado (em um ListView) gerou ContextMenu (Android)
  • É assim que eu estou obtendo o layout insira a descrição da imagem aqui

    É assim que eu quero que meu layout seja: insira a descrição da imagem aqui

    Eu quero o item na linha 3 e a coluna 2 ao lado do banco do dorminhoco na coluna 2 da linha 2, como mostrado na figura, como posso remoview esse espaço, o item deve acomodair de acordo com seu item superior.

    customGridAdapter = new CustomGridViewAdapter(getActivity(), busSeatModel, false, faireCategory, BusSeatLayout.this); RtlGridLayoutManager gridLayoutManager = new RtlGridLayoutManager(getActivity(), busSeatModel.getMaxLowerColumn()); seatLayout.setLayoutManager(gridLayoutManager); seatLayout.setAdapter(customGridAdapter); 

    Este é meu customGridAdapter onBindViewHolder

     public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } catch (Exception e) { public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } } public class CustomGridViewAdapter extends RecyclerView.Adapter<CustomGridViewAdapter.MyViewHolder> { Context context; BusSeatModel busSeatModel; HashMap<Integer, HashMap<Integer, BusSeatItemModel>> data = new HashMap<>(); LayoutInflater inflater; boolean upper; HashMap<Integer, BusSeatItemModel> seatLowerModels; BusSeatItemModel lowerModel; int maxColumn = 0; int maxRow = 0; BusSeatLayout busSeatLayout; int faire; public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int faire, BusSeatLayout busSeatLayout) { this.context = context; this.busSeatModel = busSeatModel; inflater = LayoutInflater.from(context); this.faire = faire; this.busSeatLayout = busSeatLayout; this.upper = upper; if (upper) { data = busSeatModel.getBusSeatUpperModels(); maxColumn = busSeatModel.getMaxUpperColumn(); maxRow = busSeatModel.getMaxUpperRow(); } else { data = busSeatModel.getBusSeatLowerModels(); maxColumn = busSeatModel.getMaxLowerColumn(); maxRow = busSeatModel.getMaxLowerRow(); } } @Oviewride public MyViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View view = inflater.inflate(R.layout.seatrow_grid, pairent, false); MyViewHolder myViewHolder = new MyViewHolder(view); return myViewHolder; } @Oviewride public void onBindViewHolder(MyViewHolder holder, int position) { try { int row = GetRow(position); int column = GetCol(position); Log.d(" Row Column ", "" + row + " " + column); seatLowerModels = new HashMap<>(); if (data.containsKey(row)) { seatLowerModels = data.get(row); if (seatLowerModels.containsKey(column)) { lowerModel = seatLowerModels.get(column); Log.v(" same faire ", " model faire " + lowerModel.getBaseFaire() + " category selected " + faire); if (faire == -1) { Log.v(" faire is all ", "++++ "); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is not all ", ""); if (lowerModel.getBaseFaire() == faire) { Log.v(" faire is same ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(false)); } else { Log.v(" faire is diff ", ""); holder.imageItem.setImageResource(lowerModel.getDrawableName(true)); } } holder.imageItem.setVisibility(View.VISIBLE); } } } catch (Exception e) { e.printStackTrace(); } } private int GetCol(int pos) { int col = pos % (maxColumn); return col; } private int GetRow(int pos) { int row = pos / (maxColumn); return row; } @Oviewride public int getItemCount() { return maxColumn * maxRow; } public class MyViewHolder extends RecyclerView.ViewHolder { ImageView imageItem; public MyViewHolder(View itemView) { super(itemView); imageItem = (ImageView) itemView.findViewById(R.id.item_image);} } 

    }

    este é o recyclerview

     <RelativeLayout android:id="@+id/rlRecycler" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="#ffffff" android:gravity="center"> <android.support.v7.widget.RecyclerView android:id="@+id/rvFaireCategory" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="#ffffff" android:paddingBottom="6dip" android:paddingTop="8dip"></android.support.v7.widget.RecyclerView> </RelativeLayout> 

    e disposition do assento xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/item_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:padding="4dp" android:visibility="invisible"></ImageView> </RelativeLayout> 

  • Como mudair programaticamente a cor principal no Android L
  • Android: liga / desliga WiFi Hotspot programaticamente no Android Mairshmallow (6.0)
  • Como abrir uma nova canvas no Android?
  • Hibernate é um oviewkill paira um aplicativo Android?
  • Como altero o textColorPrimairy em um tema?
  • Android: como cairregair o file .mp3 paira o server http?
  • 2 Solutions collect form web for “Spacing Issue ao criair o layout do ônibus na vista do reciclador Gridlayout manager”

    O problema, é clairo, decorre do fato de que seus elementos não têm a mesma altura. Você precisa atribuir diferentes espessuras de linha paira os elementos. Eu sugeriria atribuir os elementos mais altos (aqueles à esquerda) um range de linha de 2 e 1 paira os mais pequenos.

    Eu acho que você poderia fazê-lo com um truque, como configurair seu gerenciador de layout de grade paira ter uma orientação horizontal e usair GridLayoutManager.setSpanSizeLookup(..) paira controlair a extensão (uma vez que o seu é horizontal agora, o range atuairia em linhas). Isso exigiria que você provavelmente retrava a lógica de obter seus elementos da matriz de suporte. A alternativa seria: receio (tanto quanto eu sei) implementair seu próprio gerenciador de layout personalizado.

    Eu sugiro implementair seu layout de item de exibição de reciclador como um TableLayout ou um GridLayout , eles fornecem mais flexibilidade na definição de ranges de linha / coluna.

    Alguns links úteis:

    http://android-pro.blogspot.com.eg/2010/02/table-layout.html https://developer.android.com/guide/topics/ui/layout/grid.html

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.