0

我有一个围绕任意点旋转的图像。但我需要 3 个这样的图像同时旋转这就是我尝试实现相同的方式

private void rotateLogo(float degrees){
    Matrix matrix1 = new Matrix();
    //int radius = turntable.getWidth()/2;
    double radians = degrees* (Math.PI/180);
    double xcoordinate = 220 * Math.cos(radians)- 60;
    double ycoordinate = 220 * Math.sin(radians) + 50;
    matrix1.postRotate((int)radians, 220, 220);

    // people image
    FrameLayout.LayoutParams linLay  = (FrameLayout.LayoutParams) peopleLogo.getLayoutParams();
    linLay.bottomMargin = (int)ycoordinate + 10;
    linLay.rightMargin = (int)xcoordinate + 10;
    peopleLogo.setImageMatrix(matrix1);
    peopleLogo.setLayoutParams(linLay); 
    rotateLogo2(degrees - 2);
    }

private void rotateLogo2(float degrees){
    double radians = degrees* (Math.PI/180);
    double xcoordinate = 220 * Math.cos(radians)- 60;
    double ycoordinate = 220 * Math.sin(radians) + 50;

    // people image
    FrameLayout.LayoutParams linLay  = (FrameLayout.LayoutParams) serverLogo.getLayoutParams();
    linLay.bottomMargin = (int)ycoordinate + 10;
    linLay.rightMargin = (int)xcoordinate + 10;
    serverLogo.setLayoutParams(linLay);
}  

在上面的代码中,我减少了角度并使用相同的代码旋转了第二张图像,但图像不旋转,它只是在触摸时消失。

我还尝试在旋转之前获取第一张图像的布局参数并将其应用于第二张图像,但这也不起作用..

图像在旋转时消失,但有时它会出现然后消失

任何人都可以帮助我了解我可能错在哪里或提出任何其他相同的方法吗?

4

1 回答 1

0

您可以重构代码

private void rotateLogo(View logo, float degrees){
   Matrix matrix1 = new Matrix();
    //int radius = turntable.getWidth()/2;
    double radians = degrees* (Math.PI/180);
    double xcoordinate = 220 * Math.cos(radians)- 60;
    double ycoordinate = 220 * Math.sin(radians) + 50;
    matrix1.postRotate((int)radians, 220, 220);

    // people image
    FrameLayout.LayoutParams linLay  = (FrameLayout.LayoutParams) logo.getLayoutParams();
    linLay.bottomMargin = (int)ycoordinate + 10;
    linLay.rightMargin = (int)xcoordinate + 10;
    if (logo isInstanceOf ImageView) { 
        logo.setImageMatrix(matrix1);
    }
    logo.setLayoutParams(linLay); 
}

并使用不同的参数调用该方法两次..

rotateLogo(peopleLogo, degrees);
rotateLogo(serverLogo, degrees-2);
于 2012-06-26T06:43:33.923 回答