我一直在尝试在WebView中显示图像 . 图像可能很大,尺寸可能比设备大 . 我选择使用 Webview
,因为它能够显示大图像 .
但是,很难在布局中显示带有图像的 WebView
并将其保持在中心周围 . 使用下面的代码,图像在开始时显示在中心,但是一旦我开始双击,它就会放大并缩小并在整个屏幕上移动 . 它终于与设备碎片的顶部对齐,并且不会从那里移动 .
我在这里遗漏了一些东西 . 是否有任何具体方法可以在 WebView
中实现中心对齐的图像?
我在寻找的是:
-
Webview应该在双击切换时展开和折叠
-
图像应放大和缩小,但缩放应尊重中心的图像位置 . 当缩小时它应该回到原始位置 .
非常感谢任何帮助
这是我的布局xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="centerInside"
android:background="@android:color/holo_green_dark">
<WebView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_marginLeft = "10dp"
android:layout_marginRight = "10dp"
android:layout_gravity="center"
android:scaleType="centerInside"
/>
</FrameLayout>
这是活动源代码:
public class TestActivity7 extends Activity {
String largeURL = "http://test.png";
WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
webView = (WebView) findViewById(R.id.test);
WebSettings webSettings = webView.getSettings();
webSettings.setDisplayZoomControls(false);
webSettings.setDisplayZoomControls(false);
webSettings.setSupportZoom(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setDefaultTextEncodingName("utf-8");
// webSettings.setUseWideViewPort(true);
webView.setInitialScale(25);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadUrl(largeURL);
}
}