I apologize if this has been answered, extensive Googling found me a lot of similar but not-quite-the-same situations that didn't provide an answer. I have a WebView and would like to put a Google AdView underneath it. However, I don't want the add always attached to the bottom of the window, I want it to come AFTER the WebView, i.e. I scroll through the content of the webpage and then, underneath that, the ad is displayed. I've tried many variations of Relative and Linear layout, here's one attempt as an example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="1"/>
<com.google.android.gms.ads.AdView
android:id="#+id/web_frag_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="myUnitId"
ads:adSize="BANNER" />
</LinearLayout>
I've tried RelativeLayout with layout_below, but the WebView covers it up. It displays if I alignParentBottom, but that isn't the behavior I want. I want it to only be visible after scrolling through the content of the web page. I'm sure I'm making a simple layout mistake, and help pointing me in the right direction is greatly appreciated.
I have already done the similar thing :
1- Build your Layout like this :
<LinearLayout
... >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_weight="1"/>
<com.google.android.gms.ads.AdView
android:id="#+id/web_frag_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="myUnitId"
ads:adSize="BANNER" />
</ScrollView>
</LinearLayout>
2- Calculate the content height of your web view after the content is rendering. If you don't know how to do this, tell me, I can give you the corresponding code.
3- Set the webView.height = content.height
So your scrollview.content will adjust to the global height webView.content+web.frag_ad.height
Related
Im trying to add a a View above a webview that should scroll together with it.
Ive tried putting both views inside a scrollview like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/black" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
It worked pretty well until Ive encountered a problem in the case that the webview changes it size after it first renders (i.e. if the loaded url uses lazy loading on some of its components).
BTW it doesn't matter if the height or width of either the scroll\Linear\Web views is set to "match_parent" or "wrap_content" I still get the same problem.
Ive also tried using the "hidden" setEmbeddedTitleBar(View v) method that was introduced and then removed from the Android's WebView, in order to simply add a view above the WebView without the need of a wrapping scroll view.
I tried some hacks that were suggested here but I didn't find something that works.
Is there anyone who encunterd this problem and had find a successful way of achieving this?
Thanks a lot!
Try adding some weights to the layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="0"
android:background="#android:color/black" />
<WebView
android:id="#+id/webview"
android:layout_weight="1"
android:background="#color/brand_color"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
I don't know if it's the right way to do this but I hope you'll be able to help me.
I'm using a ListActivity to display content from RSS feed. While the content is loading I want to display a pending view. I'm using the EndlessAdapter from that website https://github.com/commonsguy/cwac-endless. It provides a way to display a pending view but the first time it loads data it's a tiny row in an empty list so it's not very sexy.
I'm actually trying to fix this up with this method :
A custom layout for my ListActivity where there is a pending view that I can hide or show for the first loading. The XML code of the layout is like this :
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:cacheColorHint="#FFFFFF"/>
<include
android:id="#+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="#layout/loading_anim">
</include>
</LinearLayout>
The first time I load data I set the list visibility to gone with this line :
listView.setVisibility(View.GONE);
It's almost working but the included layout doesn't fill the entire screen and right know I don't know how to fix this in a proper way.
Hope someone will be able to help me, thank's!
UPDATE :
I tried to set the contentview with only the loading layout (see XML below) and I got the same result (see http://imageshack.us/photo/my-images/594/loadingwf.png/) :
this.setContentView(R.layout.loading_anim);
<?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:background="#FFFFFF"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5dp" >
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="#string/loading" />
</LinearLayout>
So I'm wondering if maybe it's because of the tabs... Can anybody help me ? Thank's
UPDATE 2
I found a solution, it had nothing to do with the neverending adapter. See The content of my tabs doesn't fill the whole space
In your ListView, try this:
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:cacheColorHint="#FFFFFF"/>
What I did was set layout_height to wrap_content. Should fill your entire screen now.
I am having an issue that make me crazy
I have a listview with WebView inside. So I created a custom listview.
The WebView forbid me to click so I created a webviewclicklistener.
My problem was that when I display some images, my webviews are "shaking" as if it wants to load the image a thousand times.
In fact I discovered that the height size of some elements change like every seconds, that give a feeling of shake.
The only way I found to fix it is to give a layout:height value for my listview.
My new problem is that when I put for exemple 600dip, I have a scrollbar, but I can't look at the end of my listviews.
If I put like 1000dip, I don't have scroll bar and I can't see the end of my list neither.
Here is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/woodbackground"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Question" android:textSize="30px"></TextView>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<WebView android:id="#+id/wvplquestion" android:layout_height="wrap_content"
android:layout_width="fill_parent"></WebView>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_weight="1">
<TextView android:background="#android:color/transparent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:hint="Select Answer" android:textSize="30px"></TextView>
<ListView android:id="#+id/lvquestion" android:layout_width="fill_parent"
android:layout_height="600dip" android:prompt="#string/selectp" />
</LinearLayout>
And my custom listview layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="3dip">
<WebView android:id="#+id/weblistview" android:layout_width="fill_parent"
android:layout_height="wrap_content"></WebView>
Thanks for your help
maybe you can try to change your listview layout height. Instead of wrap content, put a fixed height. I don't know if it will be working, but you can try it. I'd a problem similar to yours and I solved it like this.
I hope it will work. Good luck ;)
Seems it mostly happens when several webviews contained into one scrollview. Seems at least first webviews should have fixed height.
I have this layout, and it's scaled weirdly (probably due to inadviseable layout nesting) if I do not use fillviewport=true in my HorizontalScrollView.
Everything works peachy (except for the odd scaling) when fillviewport=false, but when fillviewport=true, the scaling is perfect but no scrolling happens.
This is the layout (Note: I know you're not supposed to put a webview in a scrollview. But webview doesn't have a smoothscrollto nor expose a setscroller method, so ... bleh.)
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webContainer"
android:layout_below="#+id/titlebar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webZ"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</HorizontalScrollView>
Setting android:fillViewport="true" doesn't usually disable scrolling in a view, does it?
It's just supposed to be sure the scrollview fills the viewport regardless of the size of its contents, eh? I think the viewport is the visible area of the screen, and there is definitely more content off the edge of the visible area in the webview, I just can't scroll to it anymore.
I can see from logcat that the scrolling methods are being called, they just don't change the screen. (Unless I set fillviewport to false.)
The problem is that you use "fill_parent," which means "be as big as my parent." Use wrap_content for the width instead.
I encounter a similar problem with a standard ScrollView containing a WebView: the scrolling was not working anymore. Changing of fill_parent to wrap_content did not worked for me.
The example of Romain Guy is working fine when the expanded view is a TextView but is not when it's replaced by WebView.
What is not working:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0">
</WebView>
<Button
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Click">
</Button>
</LinearLayout>
</ScrollView>
When I add a small amount of data in the webview it seems ok:
But when I fill the WebView with a lot of data, it does not work as you can see below:
The button is always displayed and the scroll does not work anymore. In fact, the touch scroll does not work and the DPAD scroll works...
I did not found any reason for that but I found a workaround: it consist in adding a LinearLayout containing the WebView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout android:id="#+id/linearlayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent" android:layout_height="wrap_content">
</WebView>
</LinearLayout>
<Button
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Click">
</Button>
</LinearLayout>
</ScrollView>
Now it works fine:
The default screen of my app shows a ListView. When the user selects an entry a new Activity is displayed with a Title (TextView), some information gained from xml (WebView).
I want to place an Ad aligned to the bottom of this second Activity.
My layout currently is this:
<LinearLayout android:id="#+id/info" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" style="#style/info">
<TextView android:id="#+id/title" style="#style/title" />
<WebView android:id="#+id/info" style="#style/info" />
</LinearLayout>
This works perfectly, but I can't get the Ad to always be at the bottom.
I've tried RelativeLayout, but no matter what, I always get the same results!
If the HTML shown in the WebView is short enough for the AdView to be displayed (but not at bottom, underneath WebView) or its too long and the AdView is not shown at all!
I want the AdView always visible always, even if the WebView scrolls!
Hope this makes sense!
Neil
PS: I'll continue to look for answers and update if I find one....
Figured out a way to solve this, but is it the best way??
This is how I did it:
<LinearLayout android:id="#+id/linearlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:neildeadman="http://schemas.android.com/apk/res/com.neildeadman.android" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" style="#style/Info">
<LinearLayout android:id="#+id/info" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" style="#style/info">
<TextView android:id="#+id/title" style="#style/title" />
<WebView android:id="#+id/info" style="#style/info" />
</LinearLayout>
</LinearLayout>
The "layout_weight" attributes allowed me to force the inner LinearLayout to fill the remaining gap left by the add, which then contained my layout from above!
Works lovely....