I included a WebView in my activity and load some Javascript in it which is then going to get data from an external website.
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this. Any idea of how I should handle this?
Cheers.
Are you using scrollview in your layout? Try that and see if that helps.
Here is a link to the developer page
This works and displays fine but the problem is that my activity doesn't scroll when the WebView is done loading so I can't see the bottom of the WebView such as all the other Views I put below this.
You need to change your layout such that the "other Views I put below this" will be on the screen, and the WebView simply takes up the remaining space.
For example, here is a layout showing a WebView with a Button:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView android:id="#+id/webkit"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
/>
<Button android:id="#+id/helpcast"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View Helpcast"
/>
</LinearLayout>
Because the WebView is set up with a 0px height but a weight of 1, and because the Button specifies no weight, the WebView will fill all space left over after the Button is on-screen. The WebView content will scroll inside the WebView itself, if needed, based upon whatever Web page you load in there.
Related
I'm trying to have a webpage load but I want the user to see the page loading but be unable to interact with it until the page loads.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/mainWebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#40606060"
/>
I just thought I'd put a semi-transparent, gray layer over it which I would hide when the page has loaded. I think what I need is two views inside some sort of container. This post (Can I overlap the WebView with an ImageButton?) has a similar question but when I use a WebView I can still interact it by scrolling.So I've been using a WebView and a LinearLayout (i've tried an ImageView as well) inside a FrameLayout (I've tried a GridLayout as well).
In both cases, I can cover the WebView just like I want but I can still interact with the Webview by scrolling with my finger and I don't want that. In HTML I would just put one DIV on top of another and it would accomplish this but I'm not sure how to do the equivalent with Android.
Thanks for any help!
Just put your LinearLayout as clickeable = "true"
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#40606060"
android:clickeable="true"
/>
You can Implement WebViewClient and extend onPageFinished() as follows:
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
you can show progress dialogue when WebView start load the page and dismiss ProgressBar onPageFinished() Method.
Tell me if you have still any query...
In the webview.xml, I only have a frame layout as a wrapper for the webView as the following,
<FrameLayout
android:id="#+id/scroll_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
As a little background of the webview, it's basically a mobile web page that displays pictures, and allows for horizontal scrolling(either swiping or clicking the 'next' button). Right now, I'm able to scroll to the next photo via swiping, but once I release my finger, the photo pops back to the original photo. Same thing is happening for clicking next, the screen displays half of the next photo before scrolling back to the previous photo.
I have absolutely no idea why this is happening as I've tried all options with playing with the horizontal scrolling attributes, but it still isn't working. Could anyone who has experienced this provide some insights. Please feel free to let me know what additional info you need.
try using linear layout rather than using frame layout as you have only one child that is webview for the parent layout.
this one works for me :
<?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:id="#+id/webview_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
I wan't to indicate that my webview is loading in some way. Using the Progressbar seems like a good solution but I am not certain how to properly do this.
By Progressbar I mean a spinning thingie in Android.
This is what I know by now and what I have tried:
I know about onPageStarted(...) and onPageFinished(...) callbacks which you define inside the WebViewClient and then hide or show Progressbar based on calls to those methods. BUT this approach is creating many problems with the HTML page inside the webview. For example when I hide Progressbar HTML elements resize and than go back to their original sizes for a brief moment. This looks really ugly and I don't know why this is happening. I tried putting my Progressbar and webview inside Frame and Relative layout (in order to have the progress cantered) and with both of these I get the above problem. HTML page loading is Javascript heavy since there is http://cubiq.org/iscroll-4 library on it but I doubt it's the problem with the library since the same page loads without strange behaviours when opened in Browser app on the phone.
My main problem is that I don't know how to define a layout containing my Progressbar and webview and avoid strange zoom in/out jumps. That is why I am asking how should one show progress bar correctly over a webview.
EDIT:
This is one of the layouts I tried:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
It's more or less similar with relative layout but I use centerInPerent=true on both axes for the ProgressBar
There's an efficient way to show progress in an activity. If you are using ActionBar, then
you can set an INDETERMINATE progressbar (the spinning one), or a horizontal progressbar (as seen on web browsers like Chrome). To do this you have to set the Window Feature to appropriate values like:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
OR
requestWindowFeature(Window.FEATURE_PROGRESS);
To set the progress value, do this:
setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
Then call setProgress(int) whenever you want to change the progress value.
You can controll the visibility of the progressbar using
setProgressBarIndeterminateVisibility(true); //sets it to visible
AND
setProgressBarIndeterminateVisibility(false); //hides the progressbar
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view.
I would use a RelativeLayout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:centerInParent="true" />
</RelativeLayout>
This should work...
I have an URL to a website, which I want to load inside a WebView. The website must be scrollable up and down with the exception of the top 20dp of the page. Meaning that the header of the website must not be visible inside the WebView, without impairing the scrollability of the website overall and without overlaying the WebView with an awkward solid color View.
One solution could be to inject javascript.
mWebView.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('headerClassName')[0].style.display=\"none\"; "+
"})()");
This will hide the header, if you know the class where the header is located.
You can give a try to a tricky layout design in XML itself.
Take one FrameLayout and put WebView and a ImageView in it, Like this
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_gravity="top"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#drawable/whiteBG"/>
</FrameLayout>
I have a WebView inside the ScrollView.
The content of WebView dyanamically changes when it displays different html page.
I have the following issue:
For example I have A.html, and B.html. The content of B.html is larger than A.html, so the page is longer.
When WebView load B.html, the ScrollView stretches its size to enable itself scroll for B.html, then if I go back to A.html, ScrollView doesn't resize itself. (The scroll area is exceed the content of A.html)
What I want to have, is dynamic change the scroll area of scroll view to fit the webview's content.
Try using android:fillViewport in scroll view..!!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
After Orientation screen will resize, it works but bad in performance, not a very good solution
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
This helped me:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
That's not good idea to place WebView inside of ScrollView. WebView is smart enough to show scrollbars by itself.
Don't put a WebView inside of a ScrollView.