android - WebView 方向更改不调整网页大小

标签 android html webview resize

我正在制作一个 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/

相关文章:

Android SDK 工具修订版 22 问题?

javascript - 自动着色文本 | JS CSS HTML

jquery - 包含特定 div 的视频背景

javascript - android webview wrapp 内容不起作用,webview 在加载页面后无法设置高度

android - 我尝试使用 SmsRetrieverClient 从收到的短信中读取 OTP,但广播接收器未调用

下载并安装更新后的 Android 应用程序 ClassNotFoundException

带有全屏 WebView 的 iOS 应用程序

android - 为什么软键盘不会显示在带有 WebView 的 fragment 中

安卓 : Get view only on which touch was released

javascript - 使用页面加载器后 Wow.js 不工作