0

我创建了自定义FrameLayout。我在主体周围增加了1个主圈和5个圈。我想围绕主圈旋转圈子。在自定义FrameLayout中旋转Multi ImageView

public class Circles extends FrameLayout{ 
ImageView mMainCircle; 
ImageView mCircle0; 
ImageView mCircle1; 
ImageView mCircle2; 
ImageView mCircle3; 
ImageView mCircle4;  

public Circles(Context context) { 
    super(context, null, 0); 
    init(); 
} 

public Circles(Context context, AttributeSet attrs) { 
    super(context, attrs, 0); 
    init(); 
} 

public Circles(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    init(); 
} 

public void init(){ 
    // set positions, onClick and add 
    Cicle.setOnClickListener(mOnClickListener); 
    this.addView(mMainCircle); 
    this.addView(Circle0); 
    this.addView(Circle1); 
    this.addView(Circle2); 
    this.addView(Circle3); 
    this.addView(Circle4); 

    } 
} 

我该怎么做可以围绕主要圆圈旋转的所有圆圈。我尝试了所有的circleX setOnTouchListener,但它不起作用。

CircleX.setOnTouchListener(new OnTouchListener() { 

      public boolean onTouch(View v, MotionEvent event) { 
       switch (event.getAction()) { 
       case MotionEvent.ACTION_DOWN: 

        break; 
       case MotionEvent.ACTION_MOVE: 

        break; 
       case MotionEvent.ACTION_UP: 

        break; 
       default: 
        break; 
       } 
       return false; 
      } 
     }); 

我需要一个代码,如果有可能或例如:)

THX 套件

+0

我完全不明白你想要什么。您想要在主图像周围添加图像,o制作旋转动画,其中用户可以旋转图像环? – neworld

+0

没有动画。触摸其中一个并围绕主图像旋转。 – user1509068

回答

0
private float angle = 0f; 
    private float theta_old = 0f; 
    private RotaryKnobListener listener; 
    public interface RotaryKnobListener { 
    public void onKnobChanged(int arg); 
    } 

    public void setKnobListener(RotaryKnobListener l) { 
    listener = l; 
    } 

    private float getTheta(float x, float y) { 
    float sx = x - (obj.getWidth()/2.0f); 
    float sy = y - (obj.getHeight()/2.0f); 

    float length = (float) Math.sqrt(sx * sx + sy * sy); 
    float nx = sx/length; 
    float ny = sy/length; 
    float theta = (float) Math.atan2(ny, nx); 

    final float rad2deg = (float) (180.0/Math.PI); 
    float thetaDeg = theta * rad2deg; 

    return (thetaDeg < 0) ? thetaDeg + 360.0f : thetaDeg; 
    } 

    public void setRotateListener() { 
    mRotateImage.setOnTouchListener(new OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      float x = event.getX(0); 
      float y = event.getY(0); 
      float theta = getTheta(x, y); 

      switch (event.getAction() & MotionEvent.ACTION_MASK) { 
      case MotionEvent.ACTION_POINTER_DOWN: 
       theta_old = theta; 
       break; 
      case MotionEvent.ACTION_MOVE: 
       float delta_theta = theta - theta_old; 
       theta_old = theta; 
       int direction = (delta_theta > 0) ? 1 : -1; 
       angle += 3 * direction; 

       Log.d("Tag", "rotate angle : " + obj.getHeight()); 
       obj.setRotation(angle); 
       notifyListener(direction); 
       break; 
      } 
      return true; 
     } 
    }); 
} 

private void notifyListener(int arg) { 
    if (null != listener) 
     listener.onKnobChanged(arg); 
}