2017-07-31 35 views
-1

我實現了RecyclerView,它基於首選項值顯示可變數量的按鈕。情況是這樣的:如何修改RecyclerView中單個視圖的位置

我想什麼有

enter image description here

我現在有

enter image description here

我使用的是GridLayoutManager顯示按鈕但我對如何獲得我想要的結果有許多疑問。我嘗試過使用跨度尺寸和其他東西,但沒有結果。我應該重寫onLayoutChildren()還是有更簡單的解決方案?

回答

0

你可以試試這個:

GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3); 
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 
    @Override 
    public int getSpanSize(int position) { 
     return 3 - position % 3; 
    } 
}); 
recyclerView.setLayoutManager(gridLayoutManager); 
+0

它不工作,這並不是說我找佈局 –

相關問題