我已经使用以下代码为 TextView 实现了缩放。 但是,使用代码,即使用户在屏幕上的任意位置捏合,TextView 也会缩放。我只需要在捏合 TextView 时使捏合缩放起作用。 有人可以帮帮我吗?
我现有的代码:
@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;
}
最佳答案
尝试使用 setOnTouchListener
并覆盖 onTouch
方法,这将使 View 被触摸。
public boolean onTouch(View v, MotionEvent event) {
//v is view touched
}
关于android - 如何识别在 Android 中捏合缩放的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43495164/