0
所以,我實現了一個旋轉木馬就像Android 3D Carousel。android:camera.rotateY()神祕地扭曲旋轉木馬
現在,只要我的getChildStaticTransformation(查看孩子,轉型改造)方法是這樣的:一旦
,但正如我:
@Override
protected boolean getChildStaticTransformation(View child, Transformation transformation) {
transformation.clear();
transformation.setTransformationType(Transformation.TYPE_MATRIX);
// Center of the view
float centerX = (float)getWidth()/2, centerY = (float)getHeight()/2;
// Save camera
mCamera.save();
// Translate the item to it's coordinates
final Matrix matrix = transformation.getMatrix();
matrix.reset();
mCamera.translate(((CarouselItem)child).getItemX(), ((CarouselItem)child).getItemY(),
((CarouselItem)child).getItemZ());
// Align the item
mCamera.getMatrix(matrix);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
float[] values = new float[9];
matrix.getValues(values);
// Restore camera
mCamera.restore();
Matrix mm = new Matrix();
mm.setValues(values);
((CarouselItem)child).setCIMatrix(mm);
//http://code.google.com/p/android/issues/detail?id=35178
child.invalidate();
return true;
}
一切正常添加y軸旋轉:
@Override
protected boolean getChildStaticTransformation(View child, Transformation transformation) {
transformation.clear();
transformation.setTransformationType(Transformation.TYPE_MATRIX);
// Center of the view
float centerX = (float)getWidth()/2, centerY = (float)getHeight()/2;
// Save camera
mCamera.save();
// Translate the item to it's coordinates
final Matrix matrix = transformation.getMatrix();
matrix.reset();
mCamera.translate(((CarouselItem)child).getItemX(), ((CarouselItem)child).getItemY(),
((CarouselItem)child).getItemZ());
// rotation start
float rotationAngle = ((CarouselItem)child).getCurrentAngle();
if(rotationAngle > 90){
rotationAngle = 180 - rotationAngle;
}
if(rotationAngle < -90){
rotationAngle = 180 - rotationAngle;
rotationAngle = -1 * (360 - rotationAngle);
}
mCamera.rotateY(rotationAngle);
// rotation end
// Align the item
mCamera.getMatrix(matrix);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
float[] values = new float[9];
matrix.getValues(values);
// Restore camera
mCamera.restore();
Matrix mm = new Matrix();
mm.setValues(values);
((CarouselItem)child).setCIMatrix(mm);
//http://code.google.com/p/android/issues/detail?id=35178
child.invalidate();
return true;
}
項目的位置搞砸了,看項目的相對距離中心項目:
我的想法。任何想法這是從哪裏來的?
所以招行 ** mCamera.translate(((CarouselItem)子).getItemX(),((CarouselItem)子).getItemY(), ((CarouselItem)子).getItemZ()); * ** //旋轉結束後** **? – murkr
移動上面提到的線沒有做到這一點。旋轉木馬看起來不同,但仍然很奇怪。我切換了錯誤的行嗎? – murkr
如果我有先旋轉線,然後翻譯線,旋轉木馬項目進一步分開,項目上下(從中心項目:上升,下降,停留,上下)。 – murkr