İki sütunlu liste oluşturmak için RecyclerView ile StaggeredGridLayoutManager kullanıyorum. Ancak sol sütun ve sağ sütun arasında doğru bir marj nasıl ayarlanır. Bu kodu en üstte sağ kenar boşluğu yapmak için kullandım, ancak sütunlar arasındaki çift boşluk nasıl çözülür. RecyclerView with StaggeredGridLayoutManager ile öğeler arasında çift boşluk nasıl önlenir?
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;
}
Ve Faaliyet içinde
: Benview.getX()
kullanmayı denedim
recyclerView.addItemDecoration(new SpacesItemDecoration(20));
, her zaman 0.
Herkes bana yardımcı olabilir dönmek? Çok teşekkürler!