getChildDrawingOrder called/used erratically?

前端 未结 2 887
梦谈多话
梦谈多话 2021-01-18 09:07

I am creating an isometric map with simple tiles, and I’ve extended RelativeLayout to create a layout that holds these tiles. Really, just using a R

2条回答
  •  余生分开走
    2021-01-18 09:13

    OK, figured it out by looking at the Android source code. I had the mapping of getChildDrawingOrder: the i passed is “which child should I draw i th?” not "when should I draw child i?" The reason for the NULLs is because those children were being drawn before their own i was passed.

    I changed my code to figure out the order for all children during the onMeasure pass, saving that in a SparseIntArray, and then just returned that from getChildDrawingOrder. This works.

    Back-calculating the index in the getChildDrawingOrder function, by the way, is a bad idea unless you want to rely on the order in which the children are declared. Because if you don’t rely on that order, you have to walk through the list of children to find the one that has the appropriate x and y values, which means you have to walk through the list of children for each child. That’s an O(n²) operation (read: fairly inefficient). The mathematics are also reasonably complicated.

提交回复
热议问题