Why is my Webview resizing itself? - android

I'm a noob to android development and my webview resizes itself whenever i try to play video. In order to make the webview play video i had to add the line of code:
youtube.getSettings().setPluginState(PluginState.ON);
In my layout, I have my webview above a listview. However, now when the webview plays video it becomes fullscreen and covers listview. this was not happening before i added the line above. How do I stop my webview from resizing itself? Any help is greatly appreciated?
Here is my layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/LLvideos" >
<WebView
android:id="#+id/webViewyoutube"
android:layout_width="match_parent"
android:layout_height="350dp" >
</WebView>
<!-- List view -->
<ListView
android:id="#+id/videolist"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#00000000"
android:dividerHeight="0dp" >
</ListView>
Here is my video link
youtube.loadUrl("http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=1858951133001");

Sounds like you are have a scaling issue. Try youtube.setInitialScale(50). This should work.

Try setting the webview layout like this:
webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

Related

iframe is not display correclty in android webview

I am using Webview to display iframe in android. Below is my java code
String html = "<p><blockquote><iframe height=\"740\" src=\"https://docs.google.com/document/d/e/2PACX-1vSCZgt7yvY-9aB3RSvQqhYXE0EZ_Lp7AMTMmxlGfJP04iHBjX4A7dVVrc-b9OBX3kLWp_dLyUvNjhLa/pub?embedded=true\" width=\"100%\"> </iframe></blockquote></p>";
webview.loadData(html, "text/html",null);
below is my xml
<LinearLayout
android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<WebView
android:id="#+id/webViewPage"
android:background="#color/colorWhite"
android:layout_width="fill_parent"
android:paddingBottom="53dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
But when we run code its look like below screen
How its show margin or padding from left and right?
How can we resolve this issue?
u should make your WebView heght and width are match_parent
<LinearLayout
android:layout_width="match_parent"
android:background="#color/colorWhite"
android:layout_height="match_parent">
<WebView
android:id="#+id/webViewPage"
android:background="#color/colorWhite"
android:layout_width="match_parent"
android:paddingBottom="53dp"
android:layout_height="match_parent"
/>
</LinearLayout>
You need to change the width=\"100%\" to a value because It will not load correctly.
Just say width=\"100px\" by example and you will see that the borders are gone.

Video background on entire screen

I want to have a video background on my entire screen. Everything works correctly in java: it loops etc. The problem might be in xml.
Currently I have video on a top of the screen, it looks like this: (Video is perfeclty fitted in edges)
While my purpose is to have it entirely in my screen:
Please what should i make my xml look like to achieve my goal. Thanks.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
First you need to set the orientation to landscape since you said you purpose is in landscape mode
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // add it below super.oncreate
If this code not working check out this link
or your could set the orientation in manifest just google it
And change this in your xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:id="#+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
/>
</FrameLayout>

Webview not displaying html

My webview in my application does not show up. I went to the interwebs to find an answer, but I found nothing, just tutorials on how to use the control. I am trying to load a html file, but it is not showing.
I added the user permission 'Internet' to my manifest.
Here is my layout:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:visibility="visible" >
<WebView
android:id="#+id/wvInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
</TableLayout>
I have a file, 'filename.html' in my assets folder.
The following code is in the onCreate:
WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
wvinfo.loadUrl("file:///android_asset/filename.html");
When I load the program on my phone, nothing shows up. I also tried to load an url, "http://www.google.com" and still nothing shows. I am stumped. Any ideas?
Try the below code in your layout file
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="#+id/wvInfo"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableLayout>
My guess is that you haven't setContent the layout inside onCreate().
Try like this ...
setContentView(R.layout.webview_layout);
Why are you using a Table Layout for a Web view? Instead use a Linear or Relative Layout.
Try adding this
WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
wvinfo .getSettings().setJavaScriptEnabled(true);
wvinfo.loadUrl("file:///android_asset/filename.html");
Let me know if it works.

view pager not smooth when embedded within scrollview?

I have requirement like play store app where there is view pager with images and videos
and scroll to view details .Unfortunately when user scrolls the scroll is jumpy but if i remove the scrollview the view pager works perfectly fine .
The layout look and feel is something like this
http://cl.ly/MBRB
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:background="#drawable/loading_image"
android:gravity="top"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/product_image_pager"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/titles"
style="#style/CirclePageIndicator"
android:layout_alignParentBottom="true"
android:padding="10dip"
android:paddingBottom="10dp" />
</RelativeLayout>
<include layout="#layout/app_screen_menu" />
</LinearLayout>
</ScrollView>
Btw i am loading images from server .
Thanks
You are using 2 scrollisteners
A viewpager uses a scrolllistener
A scrollview uses a scrolllistener
These two scrollistener are fighting for the ScrollEvent.
You can solve this by implementing onInterceptTouch. In this method you can decide who wins the fight over the ScrollEvent
Take a look at this protected post regarding a similair issue containing 2 scrollviews

webview is not taking full screen

i have simple layout with two buttons as you can see in the image , when i click on google button it opens google website in the webview as you see it is not opening google website on full screen it is showing those buttons two ,but when i remove scrollbar from my main layout, then webview shows google website on the full screen, how can i fix this problem because i want to user scrollview in my main layout.. here is my main.xml
xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/btn_click_login"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="2"
android:text="Google"/>
<Button
android:id="#+id/btn_gmail"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="2"
android:text="Gmail"/>
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</WebView>
</LinearLayout>
</ScrollView>
when i click on google button it opens google website in the webview
as you see it is not opening google website on full screen
This is because probably you are using same Activity with same XML layout, where are another widgets. But solution is not difficult.
1. First create something like web.xml with one widget WebView.
2. Then create another class extending from Activity called for example WebBrowser.java
3. Add it to your Manifest.xml as <activity android:name=".WebBrowser"></activity>
4. In your WebBrowser class will set your layout with setContentView(R.layout.web) and initialize your WebView.
5. After clicking on Google Button create new Intent and start new Activity.
Intent i = new Intent(this, WebBrowser.class);
startActivity(i);
your web.xml can looks like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Note: For support of full screen you can use
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Categories

Resources