我想在我的应用程序中添加一个像路线图图像的图像.我想在缩放图像时为此图像添加缩放功能以及水平滚动.
我写了一些代码,但它只允许缩放而不是滚动.
码:
public class Zoom extends View { private Drawable image; private int zoomControler=20; public Zoom(Context context) { super(context); image=context.getResources().getDrawable(R.drawable.boothmap); setFocusable(true); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler); image.draw(canvas); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in zoomControler+=10; if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out zoomControler-=10; if(zoomControler<10) zoomControler=10; invalidate(); return true; } }
你能帮我解决这个问题吗?到目前为止我的代码是否合适还是你有更好的代码?
对我有用的是:只需在webview中添加内置缩放控件,然后调用其loadDataWithBaseURL方法.
webview.getSettings().setBuiltInZoomControls(true); webview.loadDataWithBaseURL("file:///android_asset/", "", "text/html", "utf-8", null);