我正在尝试使用 GestureScaleListener 增加 WebView 中的字体缩放。我的 WebView 在片段内。当我在片段上尝试 GestureScaleListener 时,它不起作用。我的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
scaleGestureDetector = new ScaleGestureDetector(getActivity(), new simpleOnScaleGestureListener());
}
public boolean onTouchEvent(MotionEvent event) {
Toast.makeText(getActivity(), "scaling", Toast.LENGTH_SHORT).show();
scaleGestureDetector.onTouchEvent(event);
return true;
}
public class simpleOnScaleGestureListener extends SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
Toast.makeText(getActivity(), ""+detector.getScaleFactor(), Toast.LENGTH_SHORT).show();
WebView wv = (WebView) getView().findViewById(R.id.chaptercontent);
WebSettings settings = wv.getSettings();
settings.setTextZoom((int)(settings.getTextZoom() * detector.getScaleFactor()));
return true;
}
}
当我在 Activity 上尝试相同的代码时,它工作正常。我如何让它在片段中工作?