Chandru February 2016

Giving more spacing between 3 and 4 row item in Recycler GridLayoutManager

I am using RecyclerView with GridLayoutManager as a layout for the bus ticket booking. Everything works fine but except the place where I stuck with the logics that I have to use to leave more spacing between 3 and 4 column item in all the rows. Basically my layout should be like as the screenshot attached below.

My Requirement:

enter image description here

Current Output:

enter image description here

I am also posting my complete RecyclerView GridLayoutManager for your reference as follows

MultiSelectRecyclerViewAdapter.java

public class MultiSelectRecyclerViewAdapter extends SelectableAdapter<MultiSelectRecyclerViewAdapter.ViewHolder> {

    private ArrayList<String> mArrayList;
    private Context mContext;
    private ViewHolder.ClickListener clickListener;



    public MultiSelectRecyclerViewAdapter (Context context, ArrayList<String> arrayList,ViewHolder.ClickListener clickListener) {
        this.mArrayList = arrayList;
        this.mContext = context;
        this.clickListener = clickListener;

    }

    // Create new views
    @Override
    public MultiSelectRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                             int viewType) {

        View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.row_multiselect, null);

        ViewHolder viewHolder = new ViewHolder(itemLayoutView,clickListener);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {

        viewHolder.tvName.setText(mArrayList.get (position));

            

Answers


thetonrifles February 2016

Using item decoration here could create some problems. If you are planning to handle click on the item, clicking on blank space would be interpreted as a click on items located in inner columns.

You can configure GridLayoutManager for handling one more column and handle space as a specific view type. Here I put code implementing this approach.

Hope this could help.

Post Status

Asked in February 2016
Viewed 2,928 times
Voted 5
Answered 1 times

Search




Leave an answer