【发布时间】:2011-11-07 16:32:14
【问题描述】:
我正在制作一个 android 应用程序,如果我在我的 WebView 的最顶部并且我尝试将我的手机切换到横向模式,那么它不会调整网页大小以适应我的手机屏幕。它只会占据屏幕的一半,但是如果我向下滚动一点并切换到横向模式,它就可以正常工作!
我在 Android Manifest 中有 android:configChanges="orientation" 以防止我在更改方向时重置 webview。
^^注意^^
即使您距离页面顶部十分之一英寸,它也可以正常工作,但如果您一直处于页面顶部,它将无法正常工作。
这是我遇到问题的班级:
package my.app.name;
import my.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ConverterCatalogActivity extends Activity {
WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Set the Content View */
setContentView(R.layout.main);
/* Get the WebView */
WebView wv1 = (WebView) findViewById(R.id.wv1);
/* Activate JavaScript */
wv1.getSettings().setJavaScriptEnabled(true);
wv1.canGoBack();
browser=(WebView)findViewById(R.id.wv1);
browser.loadUrl("file:///android_asset/index.html");
/* Prevent WebView from Opening the Browser */
wv1.setWebViewClient(new InsideWebViewClient());
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// We do nothing here. We're only handling this to keep orientation
// or keyboard hiding from causing the WebView activity to restart.
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if(browser.canGoBack()){
browser.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
/* Class that prevents opening the Browser */
private class InsideWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
【问题讨论】:
标签: android html webview resize