मैं दो कॉलम सूची बनाने के लिए StaggeredGridLayoutManager के साथ RecyclerView का उपयोग कर रहा हूं। लेकिन बाएं कॉलम और दाएं कॉलम के बीच सही मार्जिन कैसे सेट करें। मैंने इस कोड का उपयोग शीर्ष से सही मार्जिन करने के लिए किया है, लेकिन स्तंभों के बीच डबल स्पेस को कैसे हल किया जाए।StaggeredGridLayoutManager के साथ RecyclerView का उपयोग करते समय आइटम के बीच डबल स्पेस से कैसे बचें?
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
// Add top margin only for the first or second item to avoid double space between items
// Add top margin only for the first or second item to avoid double space between items
if((parent.getChildCount() > 0 && parent.getChildPosition(view) == 0)
|| (parent.getChildCount() > 1 && parent.getChildPosition(view) == 1))
outRect.top = space;
}
और गतिविधि में:
recyclerView.addItemDecoration(new SpacesItemDecoration(20));
मैं view.getX()
उपयोग करने के लिए कोशिश की है, यह हमेशा वापस आ 0.
किसी को भी मेरी मदद कर सकते हैं? बहुत धन्यवाद!