1
我已經使用下面的代碼實現了TextView的縮放。 但是,即使用戶捏住屏幕上的任何位置,使用代碼TextView也可以縮放。我只需要在縮放TextView時使縮放縮放工作。 有人可以幫我嗎?如何識別在Android中捏放大的視圖?
我的現有代碼:
@Override
public boolean onTouchEvent(MotionEvent event) {
// return super.onTouchEvent(event);
if (event.getPointerCount() == 2)
{
int action = event.getAction();
int pureaction = action & MotionEvent.ACTION_MASK;
if (pureaction == MotionEvent.ACTION_POINTER_DOWN)
{
mBaseDist = getDistance(event);
mBaseRatio = mRatio;
}
else
{
float delta = (getDistance(event) - mBaseDist)/STEP;
float multi = (float) Math.pow(2, delta);
mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
mTextView.setTextSize(mRatio + 13);
}
}
return true;
}