android如何放大scrollview布局
我有一个非常简单的问题,如何在包含相对布局(以任何方式)的滚动视图中放大,夹点或按钮。有什么可以让我开始的吗?您可以尝试使用dispatchTouchEvent 示例代码:android如何放大scrollview布局,android,zooming,Android,Zooming,我有一个非常简单的问题,如何在包含相对布局(以任何方式)的滚动视图中放大,夹点或按钮。有什么可以让我开始的吗?您可以尝试使用dispatchTouchEvent 示例代码: // step 1: add some instance private float mScale = 1f; private ScaleGestureDetector mScaleDetector; GestureDetector gestureDetector; //step 2: create instance
// step 1: add some instance
private float mScale = 1f;
private ScaleGestureDetector mScaleDetector;
GestureDetector gestureDetector;
//step 2: create instance from GestureDetector(this step sholude be place into onCreate())
gestureDetector = new GestureDetector(this, new GestureListener());
// animation for scalling
mScaleDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.SimpleOnScaleGestureListener()
{
@Override
public boolean onScale(ScaleGestureDetector detector)
{
float scale = 1 - detector.getScaleFactor();
float prevScale = mScale;
mScale += scale;
if (mScale < 0.1f) // Minimum scale condition:
mScale = 0.1f;
if (mScale > 10f) // Maximum scale condition:
mScale = 10f;
ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevScale, 1f / mScale, 1f / prevScale, 1f / mScale, detector.getFocusX(), detector.getFocusY());
scaleAnimation.setDuration(0);
scaleAnimation.setFillAfter(true);
ScrollView layout =(ScrollView) findViewById(R.id.scrollViewZoom);
layout.startAnimation(scaleAnimation);
return true;
}
});
// step 3: override dispatchTouchEvent()
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
super.dispatchTouchEvent(event);
mScaleDetector.onTouchEvent(event);
gestureDetector.onTouchEvent(event);
return gestureDetector.onTouchEvent(event);
}
//step 4: add private class GestureListener
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
// event when double tap occurs
@Override
public boolean onDoubleTap(MotionEvent e) {
// double tap fired.
return true;
}
}
使用TwoDScrollView并添加ScaleGetUserDetector,然后使用
ObjectAnimator anim= ObjectAnimator.ofPropertyValuesHolder(childLayout,
PropertyValuesHolder.ofFloat(View.SCALE_X,prevScale,mScale),
PropertyValuesHolder.ofFloat(View.SCALE_Y,prevScale,mScale));
anim.setDuration(0);
anim.start();
设置子轴并请求子布局以刷新父轴。在TwoDScrollView onTouchEvent中使用相同的mScale来计算availableToScroll。我在发布之前看到过,我尝试过,似乎代码不起作用,当我捏住它时,它会放大或缩小,但当我把手放回默认状态时,还有其他想法吗?无法水平滚动。