我試圖覆蓋measureChild
,GridLayoutManager
以在測量中使用特定的佈局參數。但GridLayoutManager
擁有自己的私人執行measureChild
:測量GridLayoutManager中的子節點
private void measureChild(View view, int otherDirParentSpecMode, boolean alreadyMeasured)
如果我重寫公共measureChild
在RecyclerView.LayoutManager
:
@Override
public void measureChild(View child, int widthUsed, int heightUsed) {
super.measureChild(child, widthUsed, heightUsed);
}
將永遠不會被調用。
是否可以測量GridLayoutManager
中的兒童?
無法重寫'GridLayoutManager's'measureChild',因爲它是一個'private'方法:https://github.com /安卓/ PL atform_frameworks_support/blob/master/v7/recyclerview/src/android/support/v7/widget/GridLayoutManager.java#L710 – g4s8
也許我應該用不同的方式寫它。我的意思是說,只要你修改使用'measureChild'的方法並將它們替換爲你的實現,它就可以無縫工作。在這種情況下,我認爲這只是'layoutChunk'方法 – akash93
@ g4s8,似乎手動執行是唯一的方法。檢查我編輯的答案,但我會建議不要這樣做,因爲難以維護代碼以防止將來更新庫 – akash93