2012-12-04 79 views
1

在我的應用程序中,我使用webview來顯示html頁面。 Html頁面包含YouTube視頻。 在縱向模式下,它正在加載並正常工作。但是當方向更改爲橫向模式時,頁面將再次加載(重新創建),並且html頁面中的視頻只顯示一半尺寸。我用的android:configChanges =「方向」清單文件,但沒有工作...以及當orientatation如何在android中控制webview橫向和縱向?

這裏是我的代碼...視頻應該繼續,

  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.... 
+0

那麼真正的問題是什麼?你想成爲肖像模式的視頻,或者只是旋轉屏幕而不重新加載網頁? –

+0

1.在webview中 - 顯示的html頁面.. 2.在該html頁面中,youtube video is there問題是1. whn我旋轉屏幕從portraite到landscape ...在橫向模式下,視頻只顯示一半大小2。當我正在播放視頻,它不會繼續旋轉.. – Kumar

回答

1

一種解決方案是避免旋轉。將其添加到僅在清單中修復縱向方向的活動。

android:screenOrientation="portrait" 
+0

不,我需要在兩個方向上,我沒有想到這樣的答案從你... – Kumar

0

在清單中使用它。它可能會幫助你。

android:configChanges="keyboardHidden|orientation|screenSize" 
+0

歡迎來到StackOverflow。感謝您加入社區!我們感謝您的回答。但是爲了使這個答案更好,你應該嘗試使用markdown來讓你的代碼看起來好像它是代碼,而不僅僅是文本。看看[這篇文章](https://stackoverflow.com/editing-help) –

相關問題