W = (widthOfEachItem*totalItem) + (spacingBetweenItems*(totalItem-1))
H = (heightOfTheItem*totalItem) + (spacingBetweenItems*(totalItem-1))
B. 查找GridView的中心点(Cx,Cy); Cx = 宽度/2, Cy= 高度/2。对于每一行中的每个项目,x坐标(Cx)都会改变。对于每个列中的每个项目,y坐标(Cy)都会改变。
C.
对于矩阵中位置为(0,0)的gridItem。
找到平移百分比
x% = (Cx/W)*100,y% = (Cy/W)*100
将项目从XDelta=0平移至XDelta=x%p,从YDelta=0平移至YDelta=y%p
对于矩阵中位置为(0,1)的gridItem。 GridView中心的x坐标对于此项更接近,因此我们必须减去(widthOfEachItem+spacingBetweenItems)。
Cx现在为 Cx - (widthOfEachItem+spacingBetweenItems)
在这种情况下,只有x坐标会改变。y坐标将保持不变。
找到平移百分比:
x% = (Cx/W)*100,y% = (Cy/W)*100
将项目从XDelta=0平移至XDelta=x%p,从YDelta=0平移至YDelta=y%p
对于矩阵中位置为(1,0)的gridItem。
GridView的y坐标中心对于此项更接近,因此我们必须减去(heightOfTheItem+spacingBetweenItems)。
Cy现在为 Cy - (heightOfTheItem+spacingBetweenItems)
在这种情况下,只有y坐标会改变。x坐标将保持与(0,0)处项目相同。
找到平移百分比 -
x% = (Cx/W)*100,y% = (Cy/W)*100
将项目从XDelta=0平移至XDelta=x%p,从YDelta=0平移至YDelta=y%p
对于矩阵中位置为(1,1)的grid-item。
GridView的x坐标中心对于此项更接近,因此我们必须减去(widthOfEachItem+spacingBetweenItems)。
Cx现在为 Cx - (widthOfEachItem+spacingBetweenItems)
GridView的y坐标中心对于此项更接近,因此我们必须减去(heightOfTheItem+spacingBetweenItems)。
Cy现在为 Cy - (heightOfTheItem+spacingBetweenItems)
在这种情况下,x和y坐标都会改变。
找到平移百分比 -
x% = (Cx/W)*100,y% = (Cy/W)*100;
将项目从XDelta=0平移至XDelta=x%p,从YDelta=0平移至YDelta=y%p
以此类推,计算出GridView中所有项目的x%和y%值。
对于行超出中心项的项目,toXDelta将为负数。
对于列超出中心项的项目,toYDelta将为负数。
要更精确地对齐中心项目(动画后),请考虑向GridView的中心添加和扣除每个项目的中心坐标。
将项目从原始位置平移至中心后,如果要将它们平移回其原始位置,只需使to*Delta的值成为负数。
这是我对(0,0)处GridView项目所做的:
<translate
android:duration="600"
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:toXDelta="-7.8%p"
android:toYDelta="33.40%p" />
<translate
android:duration="600"
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:startOffset="1050"
android:toXDelta="7.8%p"
android:toYDelta="-33.40%p" />