आप कुछ लेआउट गतिशील रूप में जोड़ सकते हैं, उदाहरण के लिए:
- एडाप्टर वस्तु एक क्षैतिज LinearLayout
1- एक LinearLayout बनाने हो सकता है
यहाँ उदाहरण कोड है जावा कोड में और इसे कस्टमाइज़ करें (गुरुत्वाकर्षण, ...)
2- LinearLayout
3- करने के लिए कुछ प्रतीक जोड़ने के अपने एडाप्टर के लिए LinearLayout जोड़ने
4- दोहराने 1,2,3
// : declare new horizontal linearLayout
ImageView myIcons[nomOfIcons];
// : add all icons to myIcons
for(int i=1; i<=nomOfIcons; i++){
linearLayout.addView(myIcons[i - 1]);
if(i%numOfIconsInOneHorizontalLinearLayout==0) {
results.add(linearLayout); // add linearLayout to adapter dataSet
// : declare new horizontal linearLayout
}
}
if(n%numOfIconsInOneHorizontalLinearLayout!=0) // add last linearLayout if not added in the loop
results.add(linearLayout);
mAdapter.notifyDataSetChanged(); // update adapter
यह http://stackoverflow.com/questions/34206078/center-a-cardview-in-a-recyclerview-with-only-one-element –
के समान ही लगता है क्या यह समस्या हल हो गई है? –
आपको केवल कस्टम लेआउट बनाने की आवश्यकता हो सकती है क्योंकि GridLayoutManager इससे मदद नहीं करता है। मैंने एक उत्तर पोस्ट किया लेकिन मुझे यकीन नहीं है कि यह वही है जो आप खोज रहे हैं। – Mo1989