android - 如何在android中控制webview横向和纵向?

标签 android webview

在我的应用程序中,我使用 webview 来显示 html 页面。 HTML 页面包含一个 youtube 视频。 在纵向模式下,它正在加载并正常工作。但是当方向更改为横向模式时,页面再次加载(重新创建)并且 html 页面中的视频仅显示一半大小。我在 list 文件中使用了 android:configChanges="orientation"但没有工作......而且视频应该在 orientatation 时继续

这是我的代码...,

         webb=(WebView)findViewById(R.id.weeeb1);
                 webb.getSettings().setJavaScriptEnabled(true);
                    webb.setWebChromeClient(new WebChromeClient() {
                        public void onProgressChanged(WebView view, int progress)
                        {}
                    });

                    webb.setWebViewClient(new WebViewClient() {
                        @Override
                        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                        {
                            // Handle the error
                        }

                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url)
                        {
                            view.loadUrl(url);
                            return true;
                        }
                    });
                    webb.getSettings().setPluginsEnabled(true);
                    //webb.setInitialScale(12);
                    webb.getSettings().setLoadWithOverviewMode(true);
                    webb.getSettings().setUseWideViewPort(true);
                    webb.setPadding(0,0,0,0); 
                    webb.loadUrl("file:///android_asset/index1.html");

Portrait mode

    <ScrollView android:id="@+id/row33"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/titletext"
          android:fillViewport="false"
          android:scrollbars="none"
          android:layout_weight="1"
          >
        <LinearLayout
          android:id="@+id/row35"
          android:layout_width="fill_parent"
          android:layout_height="600dp"
          android:layout_below="@+id/row33"
          android:layout_margin="8dp" 
          android:orientation="vertical" 
          android:layout_weight="1"
          >
    <LinearLayout
          android:id="@+id/row34"
          android:layout_width="fill_parent"
          android:layout_height="260dp"
          android:layout_below="@+id/row33"
          android:layout_marginLeft="6px"
          android:layout_marginRight="17px"
          android:orientation="horizontal" 
          android:layout_weight="1"
          android:background="#1C2F69"
          >


        <ImageView
            android:id="@+id/gimage1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_marginTop="10px"
            android:layout_marginLeft="30px"
            android:layout_marginRight="10px"
            android:layout_marginBottom="10px"
            android:background="@drawable/natureimage4"
            />

        <ImageView
            android:id="@+id/gimage2"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_marginTop="10px"
            android:layout_marginLeft="10px"
            android:layout_marginRight="30px"
            android:layout_marginBottom="10px"
            android:background="@drawable/natureimage5"
            />

     </LinearLayout>
      <WebView 
         android:id="@+id/weeeb1" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
          android:layout_marginLeft="6px"
          android:layout_marginRight="17px"
          android:layout_marginTop="5px"
          android:layout_marginBottom="29dp"
         android:layout_below="@+id/row35"
          android:layout_weight="1"
         />
         </LinearLayout>
     </ScrollView>


Landscape mode

<ScrollView android:id="@+id/row33"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/titlemain"
      android:fillViewport="false"
      android:scrollbars="none"
      android:layout_weight="1">
    <LinearLayout
      android:id="@+id/row35"
      android:layout_width="fill_parent"
      android:layout_height="600dp"
      android:layout_below="@+id/row33"
      android:layout_marginLeft="190dp" 
      android:layout_marginRight="190dp"
      android:layout_marginTop="5dp"
      android:orientation="vertical" 
      android:layout_weight="1">
<LinearLayout

          android:id="@+id/row34"
          android:layout_width="fill_parent"
          android:layout_height="200dp"
          android:layout_below="@+id/row33"
          android:orientation="horizontal" 
          android:layout_weight="1"
          android:background="#1C2F69">


        <ImageView
            android:id="@+id/gimage1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_marginTop="10px"
            android:layout_marginLeft="35px"
            android:layout_marginRight="25px"
            android:layout_marginBottom="10px"
            android:background="@drawable/natureimage4" />

        <ImageView
            android:id="@+id/gimage2"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_marginTop="10px"
            android:layout_marginLeft="25px"
            android:layout_marginRight="35px"
            android:layout_marginBottom="10px"
            android:background="@drawable/natureimage5" />

     </LinearLayout>
      <WebView 
         android:id="@+id/weeeb1" 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_marginBottom="9dp"
         android:layout_below="@+id/row35"
         android:layout_weight="1" />
         </LinearLayout>
     </ScrollView>


Please suggest me the solution....

最佳答案

一种解决方案是避免旋转。添加此项以仅在 list 中修复纵向 Activity 。

android:screenOrientation="portrait"

关于android - 如何在android中控制webview横向和纵向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13702214/

相关文章:

Android Firebase 上传图片错误的 URL(问题 : X-Goog-Upload-Comment header is missing)

javascript - js navigator.geolocation.getCurrentLocation() 的 Cocoa WebView 显示权限对话框

javascript - 将数据从 Android 代码传递到从外部 URL 加载的 Javascript 方法?

android - 我如何知道加载的 URL 在 Android 中具有方法类型 POST?

javascript - 如何清除 react native webview cookies?

android - react native react 导航安全区域问题

android - 没有 Intent 接收器设置 Urban AirShip

java - 将字符串转换为 JSON 数组

java - 如何在单击按钮时将数据写入特征?

ios - NSURL WebView 未加载