我希望有一个用户界面可以绘制一些图形项目,用户可以用手势滚动和缩放图形场景(比如谷歌地图)。我在Qt中使用了图形框架,但我找不到类似的东西机器人。
我喜欢Dragging and Scaling并在开发人员中示例 InteractiveChart ,但它似乎很复杂。我试图通过mysely实现。这是一些片段。我使用ScaleGestureDetector和GestureDetector来更改参数mContent,mContent是一个FrameLayout.It功能但有一些bug。我想要一些建议,谢谢!
private final ScaleGestureDetector.OnScaleGestureListener mScaleGestureListener
= new ScaleGestureDetector.SimpleOnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {
float scaleFactor = detector.getScaleFactor();//This value is defined as (getCurrentSpan() / getPreviousSpan())
float factor = scaleFactor / lastScaleFactor;
Log.d(TAG, "factor+" + factor);
lastScaleFactor=scaleFactor;
scale*= factor;
mContent.setScaleX(scale);
mContent.setScaleY(scale);
return super.onScale(detector);
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
mContent.setPivotX(detector.getFocusX());
mContent.setPivotY(detector.getFocusY());
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
lastScaleFactor=1;
}
};
private final GestureDetector.SimpleOnGestureListener mGestureListener
= new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
mContent.scrollBy((int)distanceX,(int)distanceY);
return true;
}
};