WebView Orientation change issue

后端 未结 4 679
小鲜肉
小鲜肉 2021-01-20 11:12

I have a layout below where i have a linear layout with gravity as center to make the child center aligned.I want to add a webview programatically and loading the youtube vi

4条回答
  •  面向向阳花
    2021-01-20 11:46

    Well, I may be too late. But, what I do :

    AndroidManifest.xml

    android:configChanges="orientation"

    WebViewContainerActivity.java

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        /* WebView mainView is declared globally */
        ConstraintLayout lana = findViewById(R.id.main);
        lana.removeView(mainView);
        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int screenWidth = displaymetrics.widthPixels;
        int screenHeight = displaymetrics.heightPixels;
        lana.addView(mainView, 0,
                new ConstraintLayout.LayoutParams(
                        screenWidth,
                        screenHeight));
        super.onConfigurationChanged(newConfig);
    }
    

    It does it's work efficiently, and I must use this because I don't understand HTML.

提交回复
热议问题