title: Moving and rotating a triangle simultaneously around a circle: Android
body: <p>I have a triangle image whose one edge is always in the same direction as the circle. 
  This image has to be moved around the circle based on user swipe/drag. So, it has to both rotate (so that it's edge is in same direction as the circle) and at the same time revolve around the circle.</p>
  
  <p>How to implement this feature?</p>
  
  <p>UPDATE: My custom View is as follows:</p>
  
  <pre><code>public class ThermoView extends FrameLayout{
  
      private ImageView mThermoBgrd;
      private ImageView mCurTempArrow;
      public static final int THEMROSTAT_BACKGROUND = 0;
      public static final int THEMROSTAT_CURR_TEMP = 1;
  
  
  
      public ThermostatView(Context context, AttributeSet attrs) {
          super(context, attrs);
  
          mThermoBgrd = new ImageView(context);
          mThermoBgrd.setImageResource(R.drawable.circle_icon);
  
          addView(mThermoBgrd, ThermostatView.THEMROSTAT_BACKGROUND);
  
  
          mCurTempArrow = new ImageView(context);
          mCurTempArrow.setImageResource(R.drawable.ruler_triangle_icon);
          mCurTempArrow.setScaleType(ImageView.ScaleType.MATRIX);
          addView(mCurTempArrow, ThermostatView.THEMROSTAT_CURR_TEMP, new LayoutParams(50, 50));
  
  
      }
  
      @Override
      protected void onLayout(boolean changed, int left, int top, int right,
              int bottom) {
          super.onLayout(changed, left, top, right, bottom);
  
          int currTempHeight = mCurTempArrow.getMeasuredHeight();
          int currTempWidth = mCurTempArrow.getMeasuredWidth();
  
  
          int parentWidth = right - left;
          int parentHeight = bottom - top;
          int padding = currTempHeight;
  
          //We need square container for the circle.
          int containerLeft = padding;
          int containerTop = parentHeight - parentWidth + padding;
          int containerRight = parentWidth - padding;
          int containerBottom = parentHeight - padding;
          int containerWidth = containerRight - containerLeft;
          int containerHeight = containerBottom - containerTop;
  
  
          //place the arrow indicating current temperature
          int curTempLeft = containerRight - ((containerWidth/2) + currTempWidth/2);
          int curTempTop = containerTop - (currTempHeight/2);
          int curTempRight = curTempLeft + currTempWidth;
          int curTempBottom = curTempTop + currTempHeight;
  
          mCurTempArrow.layout(curTempLeft, curTempTop, curTempRight, curTempBottom);
  
      }
  </code></pre>