我正在实现一个小项目,我在我的 web 视图中显示本地图像(为了使用缩放和平移功能),然后单击按钮,将加载下一个图像。我可以加载图像,但在按钮上单击我无法使用新图像重新加载 web 视图。
任何建议都会非常有帮助。:)
下面是我的 WebViewActivity.java 代码:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view_activity);
// Initialize all View Components
flippy = (ViewFlipper)findViewById(R.id.viewFlipper1);
WebView mWebView = (WebView) findViewById(R.id.webView);
next = (ImageButton)findViewById(R.id.next);
next.setAlpha(100);
previous = (ImageButton)findViewById(R.id.previous);
previous.setAlpha(100);
mWebView.setInitialScale(0);
WebSettings webSettings = mWebView.getSettings();
webSettings.setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/start.png");
mWebView.getSettings().setBuiltInZoomControls(true);
}
public void onClickFeature (View v)
{
int id = v.getId ();
switch (id) {
case R.id.next :
imagename = /*nextImagename*/;
mWebView.loadUrl(imagename)
flippy.showNext();
break;
case R.id.previous:
imagename = /*previousImagename*/;
mWebView.loadUrl(imagename)
flippy.showNext();
break;
default:
break;
}
}
以下是 web_view_activity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
<ImageButton
android:id="@+id/previous"
android:layout_width="59dp"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:background="@null"
android:onClick="onClickFeature"
android:src="@drawable/previous" />
<ImageButton
android:id="@+id/next"
android:layout_width="59dp"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:background="@null"
android:onClick="onClickFeature"
android:src="@drawable/next" />