我正在开发我的第一个应用程序,它使用显示名称的列表活动。
当我单击其中一个列表项时,它会打开一个新的意图(活动?),它调用包含 textview 的 xml 布局。
我想要实现的是让 pinchzoom 与 textviews(或类似的东西)一起工作
今天,终于,我遇到了一个用 textviews 来做的版本,但是我的语言还不够好,还不能自己实现整个类。
我找到了本教程,但我似乎无法弄清楚如何使用它: http ://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part -6-实现捏缩放手势/1847
任何人都可以帮助我使用 MyGestureDetector() 获取此代码:
private GestureDetector gestureDetector;
private View.OnTouchListener gestureListener;
在 onCreate 中:
// Zoom handlers
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
// We can be in one of these 2 states
static final int NONE = 0;
static final int ZOOM = 1;
int mode = NONE;
static final int MIN_FONT_SIZE = 10;
static final int MAX_FONT_SIZE = 50;
float oldDist = 1f;
@Override
public boolean onTouch(View v, MotionEvent event) {
TextView textView = (TextView) findViewById(R.id.text);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
Log.d(TAG, "oldDist=" + oldDist);
if (oldDist > 10f) {
mode = ZOOM;
Log.d(TAG, "mode=ZOOM" );
}
break;
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
break;
case MotionEvent.ACTION_MOVE:
if (mode == ZOOM) {
float newDist = spacing(event);
// If you want to tweak font scaling, this is the place to go.
if (newDist > 10f) {
float scale = newDist / oldDist;
if (scale > 1) {
scale = 1.1f;
} else if (scale < 1) {
scale = 0.95f;
}
float currentSize = textView.getTextSize() * scale;
if ((currentSize < MAX_FONT_SIZE && currentSize > MIN_FONT_SIZE)
||(currentSize >= MAX_FONT_SIZE && scale < 1)
|| (currentSize <= MIN_FONT_SIZE && scale > 1)) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, currentSize);
}
}
}
break;
}
return false;
}
谢谢!