我有两个观点。一个是WebView,另一个是ImageView。我为WebView设置了自动缩放控件,如下所示:
webview.getSettings().setBuiltInZoomControls(true);
我只是使用GONE
和Visible
更改了两个观看次数的展示次数。在将我的视图从WebView更改为ImageView时,缩放控件在一段时间内不会失去其可见性。
有没有办法隐藏和显示Autozoomcontrols?
编辑:
我试过这些方法,但它仍然没有用。
webview.getZoomControls().setVisibility(View.GONE);
webview.getZoomControls().invalidate();
答案 0 :(得分:3)
public void setZoomControlGone(View view){
Class<?> classType;
Field field;
try {
classType = WebView.class;
field = classType.getDeclaredField("mZoomButtonsController");
field.setAccessible(true);
ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(view);
mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
try {
field.set(view, mZoomButtonsController);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
答案 1 :(得分:0)
您可以从WebView.getZoomControls()获取视图,并将其作为子项添加到webview旁边(或顶部)的布局中。不幸的是,它是hacky,不推荐使用getZoomControls,除非你调用WebSettings.setBuildInZoomControls(true)(这将添加你不想要的第二个缩放控件视图),否则你不会得到缩放缩放,但它似乎有效。这是我的代码,这是为了它的价值:
布局xml:
<RelativeLayout android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:id="@+id/wv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<FrameLayout android:id="@+id/wv_zoom_fl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Java(在活动中):
WebView wv = (WebView)findViewById(R.id.wv);
FrameLayout zoomfl = (FrameLayout)findViewById(R.id.wv_zoom_fl);
zoomfl.removeAllViews();
zoomfl.addView(wv.getZoomControls());
现在让缩放消失,您可以将R.id.rl(包含WebView和包含缩放控制的FrameLayout)的可见性设置为RelativeLayout.GONE。
对于一个不理解的解决方案:如果您的最小Api设置为11级(3.0 Honeycomb,那么不幸的是,这不太可能),您可以使用: http://developer.android.com/reference/android/webkit/WebSettings.html#setDisplayZoomControls(boolean)
答案 2 :(得分:-3)
我想这会奏效。
webView.getSettings().setUseWideViewPort(true);