हम किसी भी बाहरी पुस्तकालय की आवश्यकता होगी, न लिया जाए इसके लिए एंड्रॉइड के मूल रीसाइक्लर व्यू रीसायकलर व्यू लेआउट मैनेजर
को बदलकर बस एक चिड़ियाघर चिनाई लेआउट को कार्यान्वित करता है
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
RecyclerAdapter adapter = new RecyclerAdapter(this);
mRecyclerView.setAdapter(adapter);
कूल। यह बहुत आसान है, लेकिन मेरे LinearLayout पर मार्जिन काम नहीं लग रहा था। तो यहाँ एक त्वरित फिक्स है।
SpacesItemDecoration decoration = new SpacesItemDecoration(16);
mRecyclerView.addItemDecoration(decoration);
SpacesItemDecoration वर्ग:
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private final int mSpace;
public SpacesItemDecoration(int space) {
this.mSpace = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = mSpace;
outRect.right = mSpace;
outRect.bottom = mSpace;
// Add top margin only for the first item to avoid double space between items
if (parent.getChildAdapterPosition(view) == 0)
outRect.top = mSpace;
}
}
Github link of example
स्रोत
2017-08-19 07:37:44
आप समाधान मिला? –
समाधान यह है कि मैं एक कस्टम एडाप्टर व्यू घटक बना रहा हूं। जब मैं इसे पूरा कर दूंगा, तो मैं घटक को जिथूब पर साझा करूंगा। – Matroska
धन्यवाद, कृपया अपना महान कोड यहां पोस्ट करें –