bạn có thể thêm một số bố trí tự động, ví dụ:
- đối tượng bộ chuyển đổi có thể là một LinearLayout ngang
1- tạo ra một LinearLayout trong mã java và tùy chỉnh nó (trọng lực, ...)
2- thêm một số biểu tượng để LinearLayout
3- thêm LinearLayout để adapter của bạn
4- lặp lại 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
Nó có vẻ khá giống với http://stackoverflow.com/questions/34206078/center-a-cardview-in-a-recyclerview-with-only-one-element –
Vấn đề này đã được giải quyết chưa? –
bạn có thể chỉ cần tạo một LayoutManager tùy chỉnh vì GridLayoutManager không hỗ trợ điều này. Tôi đã đăng một câu trả lời nhưng tôi không chắc chắn nếu nó chính xác những gì bạn đang tìm kiếm. – Mo1989