Używam widok recykler z GirdLayout Managera do tworzenia układu magistraliRozstaw Problem podczas tworzenia układu magistrali w widoku recyklera GridLayout kierownika
mój problem jest z rozstawem mam wypełniania danych zgodnie z rzędu kolumna
ten jest jak dostaję graficzny wzór
ten sposób chcę mój układ będzie:
Chcę, aby przedmiot w rzędzie 3 i kolumnie 2 obok miejsca do spania w rzędzie 2 kolumnie 0, jak pokazano na rysunku , w jaki sposób mogę usunąć to miejsce, przedmiot powinien się dostosować zgodnie z jego górnym elementem.
customGridAdapter = new CustomGridViewAdapter(getActivity(), busSeatModel, false, fareCategory, BusSeatLayout.this);
RtlGridLayoutManager gridLayoutManager = new RtlGridLayoutManager(getActivity(), busSeatModel.getMaxLowerColumn());
seatLayout.setLayoutManager(gridLayoutManager);
seatLayout.setAdapter(customGridAdapter);
to moja 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 fare;
public CustomGridViewAdapter(Context context, BusSeatModel busSeatModel, boolean upper, int fare, BusSeatLayout busSeatLayout) {
this.context = context;
this.busSeatModel = busSeatModel;
inflater = LayoutInflater.from(context);
this.fare = fare;
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();
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.seatrow_grid, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
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 fare ", " model fare " + lowerModel.getBaseFare() + " category selected " + fare);
if (fare == -1) {
Log.v(" fare is all ", "++++ ");
holder.imageItem.setImageResource(lowerModel.getDrawableName(false));
} else {
Log.v(" fare is not all ", "");
if (lowerModel.getBaseFare() == fare) {
Log.v(" fare is same ", "");
holder.imageItem.setImageResource(lowerModel.getDrawableName(false));
} else {
Log.v(" fare 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;
}
@Override
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);}
}
}
to recyclerview
<RelativeLayout
android:id="@+id/rlRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvFareCategory"
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>
i układ siedzenia 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>
Wyślij swój kod * xml układ *. –
@jayroider Mam zaktualizowany kod xml –
Czy te wiersze są dodawane dynamicznie lub przy użyciu tego samego * układu *? –