SoFunction
Updated on 2025-04-09

Android's scaling processing instance code through gesture implementation


 /**
 * ...
 *
 * @author vlinux
 *
 */
public class MultiTouchTestActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  (savedInstanceState);
  // setContentView();
  View view = new MultiTouchView(this);
  setContentView(view);
 }

 class MultiTouchView extends View {

  private float x1;
  private float y1;
  private float x2;
  private float y2;

  public MultiTouchView(Context context) {
   super(context);
   // TODO Auto-generated constructor stub
  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {
   // TODO Auto-generated method stub

   float size = ();

   int szi = (int) size;
   int dxi = szi >> 12;
   int dyit = ((1 << 12) - 1);
   int dyi = szi & dyit;

   DisplayMetrics metrics = getResources().getDisplayMetrics();
   float dx = * dxi / (float) dyit;
   float dy = * dyi / (float) dyit;

   x1 = ();
   y1 = ();

   x2 = x1 + dx;
   y2 = y1 + dy;

   invalidate();

   return true;
  }

  @Override
  protected void onDraw(Canvas canvas) {
   // TODO Auto-generated method stub
   (canvas);

   float r = (float) ((x1 - x2) * (x1 - x2) + (y1 - y2)
     * (y1 - y2)) / 2;
   r = 50 >= r ? 50 : r;

   Paint paint = new Paint();
   ();
   (x1, y1, r, paint);

  }

 }

}