0

我想知道是否有辦法,我可以定製的Android gridlayoutmanager有水平佈局這樣的草圖: enter image description hereGridLayoutManager定製

我嘗試了一些佈局管理他們的,我在Github上找到,但不認爲幫助我執行這種佈局管理器。

是這樣的:

public class CustomLayoutManager extends StaggeredGridLayoutManager { 
public CustomLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super(context, attrs, defStyleAttr, defStyleRes); 
} 

public CustomLayoutManager(int spanCount, int orientation) { 
    super(spanCount, orientation); 
} 

@Override 
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { 
    super.onMeasure(recycler, state, widthSpec, heightSpec); 
} 

@Override 
public void setSpanCount(int spanCount) { 
    super.setSpanCount(spanCount); 
}} 

任何幫助將不勝感激 感謝

+0

您可以在適配器中使用多種類型的佈局。 –

+0

我無法更改適配器設置。它是在Android電視環境 – destrat18

+0

如果我的答案幫助你,請將其標記爲已接受。 :) –

回答

1

我不認爲你需要的CustomLayoutManager。這樣做到RecyclerView

GridLayoutManager layoutManager = new GridLayoutManager(itemView.getContext(), 2, GridLayoutManager.HORIZONTAL, false); 
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 
     @Override 
     public int getSpanSize(int position) { 
      return position == 0 ? 2 : 1;//put your condition here 
     } 
    }); 
recyclerView.setLayoutManager(layoutManager); 
+1

謝謝,它工作得很好 – destrat18

相關問題