我正在制作一个 Android 应用程序,如果我在我的 WebView 的最顶部并且我尝试将我的手机切换到横向模式,那么它不会调整网页大小以适合我的手机屏幕。它只会占据屏幕的一半,但如果我向下滚动一点并切换到横向模式,它就可以正常工作!
我在 Android Manifest 中有 android:configChanges="orientation"
以防止在我更改方向时重置 webview。
^^注^^
即使您离页面顶部只有十分之一英寸,它也能正常工作,但如果您一直在页面顶部,它就无法工作。
这是我遇到问题的类(class):
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;
}
}
}
最佳答案
我以前遇到过 WebViews 这样做的问题。尝试测量 OnOrientationChanged
中的 View ,它可能会解决您的问题!
关于android - WebView 方向更改不调整网页大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8039493/