[英]Adding some space between 2 rows of a GridLayout
// here is my grid adapter
public class TimeSlotAdapter extends RecyclerView.Adapter {
private LayoutInflater mInflater;
private String strSelectedDate;
List<Boolean> numberList;
private List<String> mData;
private TextView timetv;
List<RelativeLayout> activeTimeSlotsArray=new ArrayList<RelativeLayout>();
// data is passed into the constructor
public TimeSlotAdapter(Context context, List<String> data, String strSelectedDate,TextView timetv,List<Boolean> numberList) {
this.mInflater = LayoutInflater.from(context);
this.mData = data;
this.strSelectedDate = strSelectedDate;
this.timetv=timetv;
this.numberList=numberList;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
return new listViewHolder(view);
}
@SuppressLint("ResourceAsColor")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if(position==5||position==11){
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(0,0,0,100);
((listViewHolder)holder).timeslot.setLayoutParams(params);
}
((listViewHolder) holder).radioButton.setText(mData.get(position));
((listViewHolder)holder).radioButton.setTextColor(R.color.inactiveslots);
((listViewHolder) holder).timeslot.setBackgroundResource(R.drawable.inactive_slots);
}
@Override
public int getItemCount() {
return mData.size();
}
private class listViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
RadioButton radioButton;
RelativeLayout timeslot;
String strStartTime;
int selectedPosition;
public listViewHolder(View itemView) {
super(itemView);
radioButton = itemView.findViewById(R.id.radioBtton);
timeslot = itemView.findViewById(R.id.mslot1);
timeslot.setOnClickListener(this);
radioButton.setOnClickListener(this);
}
}
當我試圖給空間的大小button
在位置5和11是changed.Here我給的空間gridlayout
,但按鈕的大小,我不想改變它應該是相同的size.Also我需要空間grid
兩rows
之間
嘗試這個:
LayoutParams params = ((listViewHolder)holder).timeslot.getLayoutParams();
params.setMargins(0,0,0,100);
((listViewHolder)holder).timeslot.setLayoutParams(params);
並檢查R.layout.grid_item
文件,如果radioButton
layout_width屬性是wrap_content
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.