1

我是新手,所以不要怪我。我正在尝试开发一个可以制作音乐的 android 应用程序。我正在尝试制作一个在以圆形形式显示的一堆按钮上旋转的条形图,并且当它播放每个按钮所代表的声音时。但是到目前为止,我设法通过设置代表圆心的 x 和 y 坐标来使图像围绕屏幕中间旋转,但是当我尝试输入公式时 (x + radius*sin(angle)), (y + radius*cos(angle)),它只是移动我想在那个点旋转的图像。所以基本上我试图围绕由按钮或坐标定义的圆圈而不是实际的圆圈图像来旋转图像。所以我需要围绕一个圆圈旋转一个图像或图像视图,而不仅仅是一个点。

我也添加了代码,所以你可以看看我做错了什么。

ImageView bara = (ImageView) findViewById(R.id.floating_image);

layoutParams[9] = new RelativeLayout.LayoutParams

(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

        toop = Math.round(size.x/2);      // + 90*Math.sin(ANGLE)); 
        lefft = Math.round(size.y/2);    // + 90*Math.cos(ANGLE)); 
        top = (int) toop;
        left = (int) lefft;
        layoutParams[9].setMargins(top, left, 0, 0);
        bara.setLayoutParams(layoutParams[9]);
        RotateAnimation rAnim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF,  0 , Animation.RELATIVE_TO_SELF, 0);
        rAnim.setRepeatCount(Animation.INFINITE);
        rAnim.setInterpolator(new LinearInterpolator());
        rAnim.setDuration(8000);
        bara.startAnimation(rAnim);

任何帮助将非常感激 !!

4

2 回答 2

0

x^2 + y^2 = r^2

参考: http: //www.mathwarehouse.com/geometry/circle/equation-of-a-circle.php

对于您选择的 r 值(圆的半径),您应该围绕满足该方程的所有 (x,y) 为对象的中心设置动画。

我不是图形专家,所以请原谅我的回答过于简洁。

于 2013-01-20T10:53:42.730 回答
0

代码如下:

    private float mCalcX;//x-coord of object
    private float mCalcY;//y-coord of object
    private double mCenterX;//x-coord of center of circle
    private double mCenterY;//y-coord of center of circle
    private double mRadius;//circle radius
    private double mAngleRadians;//angle of your object to draw in RADs

    // whenever you draw the object, calculate the new X and Y coords
    mCalcX = (float) (mCenterX+(mRadius*Math.cos(mAngleRadians)));
    mCalcY = (float) (mCenterY+(mRadius*Math.sin(mAngleRadians)));

    public void setRadius(double r)
    {
        mRadius = r;
    }

    public void setStartingAngle(double radians)
    {
        mAngleRadians = radians;
    }

    public void setRotationSpeed(double radians)
    {
        mRotationSpeed = radians;
    }

    public void increaseRotationAngle()
    {
        mAngleRadians += mRotationSpeed;
    }

    public void decreaseRotationAngle()
    {
        mAngleRadians -= mRotationSpeed;
    }
于 2015-05-26T07:43:26.093 回答