Reputation: 21
In my application, I am using webview for displaying html page. Html page contains an youtube video. In portrait mode, it is loading and working properly.But when the orientation changes to landscape mode, the page is again loading (recreating) and video in html page is displaying only half size. I used android:configChanges="orientation" in manifest file but not working...and also video should continue when orientatation
Here is my code...,
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....
Upvotes: 1
Views: 9801
Reputation: 1411
One solution is to avoid rotation. Add this to fix the activity for portrait orientation only in manifest.
android:screenOrientation="portrait"
Upvotes: 1
Reputation: 1
Use this in your manifest. It may help you.
android:configChanges="keyboardHidden|orientation|screenSize"
Upvotes: 0