Align AdView (AdMob) to bottom of screen with WebView on Android Layout - android

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

Related

android : when is webview ready to layout?

My activity consists of a WebView and a couple buttons. I'm trying to display the buttons at the bottom of the activity, but ensure that the user must scroll through the content if it is taller than the screen. As part of my solution I have set the WebView's layout_height attribute to wrap_content.
Problem is, even though I call WebView.loadData() from within onCreate(), the WebView does not size itself right away. In the case where the web content is taller than the screen, the buttons initially appear at the bottom of the activity, and then move off-screen when the web content appears. I want to prevent the buttons from appearing at all before the web content is sized, so that when they do appear they always appear in the right place. To this end I have tried using onPageFinished (it gets called too early) and onPictureListener (it is never called at all).
How can I determine when the WebView is ready for layout?
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.webkit.WebView
android:id="#+id/wv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/btns"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="bottom" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickButton1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickButton2" />
</LinearLayout>
</LinearLayout>
</ScrollView>

setting focus on top of scrollview after an action happens android

In my app I am making some computations. The whole layout is inside a Scrollview.
The result is being shown on top. Xml is like that:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back2back"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="526dp"
android:background="#drawable/back4"
android:orientation="vertical" >
<TextView
android:id="#+id/nothing"
android:layout_width="181dp"
android:layout_height="51dp"
android:layout_gravity="center"
android:textColor="#000000"
android:textStyle="bold" />
rest of the xml
</LinearLayout>
</ScrollView>
So I want when pressing the calculate button the focus of the screen to be set to the top of my page (or to be more specific in the upper textview) so the user will be able to see a result. I searched in SO but I have not found something similar.
If I understand your question, simply call:
scrollView.scrollTo(0, 0);
in your calculation Button's OnClickListener.

Android - How to enable full page scrolling on a layout with a ListView?

I have a layout with a ListView. The list scrolls fine, but sometimes the other content on the page needs to be bigger and either the list or the other content take up too much of the screen so I need it all to scroll.
Can that be done?
Here is the layout I have so far:
<?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"
>
<include android:id="#+id/header"
layout="#layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<TextView
android:id="#+id/view_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Business:"
/>
<TextView
android:id="#+id/business_privacy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading..."
/>
<TextView
android:id="#+id/think"
android:layout_width="fill_parent"
android:layout_marginTop ="5dp"
android:textColor="#color/light_best_blue"
android:paddingLeft="10px"
android:layout_height="wrap_content"
android:text="Fill out each section below"
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px"
>
</ListView>
</LinearLayout>
What would be the way to make it easy for the user to be able to see both the text and the list even if the text takes up the whole screen? Can I make the text scrollable? It is especially bad in horizontal view so I think there must be some ux patters to make it play nicely.
Thanks for the advice!
1- Put textview which has a larger text in header of the list view so it get scroll with list...
or
2- put the textview in other scroll view with fixed size like 1/3 of the screen.
You could either make the content wrap, or wrap the content up using a HorizontalScrollView. Android docs on it can be found here.

Android GridView with ads below

I'm trying to integrate ads (admob) into my Android app. It's mostly working, except for one issue with the layout. My layout consists of:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res/com.example.photos">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/status_layout">
<ImageView android:id="#+id/cardStatus"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="#string/hello"
android:id="#+id/cardStatusText" />
</LinearLayout>
<GridView android:id="#+id/imageGridView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:numColumns="auto_fit"
android:columnWidth="100dp" android:stretchMode="columnWidth"
android:gravity="center" android:layout_below="#id/status_layout" />
<!-- Place an AdMob ad at the bottom of the screen. -->
<!-- It has white text on a black background. -->
<!-- The description of the surrounding context is 'Android game'. -->
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" app:backgroundColor="#000000"
app:primaryTextColor="#FFFFFF" app:secondaryTextColor="#CCCCCC"
app:keywords="Android Photo" />
</RelativeLayout>
The ads are shown at the bottom of the screen, just as I want. However, they seem to be overlayed or drawn on top of the bottom portion of the grid view. I would like the gridview to be shorter, so that the ad can fill the bottom portion of the screen, and not hide part of the gridview. The problem is most annoying when you scroll all the way to the bottom of the gridview, and you still cannot fully see the last row items in the grid due to the ad.
I'm not sure if this is the standard way that AdMob ads work. If this is the case, adding some padding to the bottom of the grid (if that's possible) would due the trick. That way the user can scroll a bit further, and see the last row in addition to the ad.
I just switched from using LinearLayout to RelativeLayout after reading some similar issues with ListViews. Now my ad is along the bottom instead of above the grid, so I'm getting closer.
Thoughts?
-Kevin
put this property in your gridview
android:layout_above="#+id/ad"

Android layout issue with buttons below WebView

So I have a webview I'd like to display as a dialog. I'd like the webview to fill the entire screen, except for a button below it that I'd like to stay at the bottom of the dialog regardless of how much content is in the webview. Currently my webview fills up the dialog just enough to push the button off the screen. I'm sure this is something pretty easy but for the life of me, I haven't been able to find the magical combination of layouts, views and attribute values to get it to play nice. Just to be clear, I've gotten it so the button floats over the webview but I'd like the webview to stop just above the button and scroll, if that makes sense.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
You will want to use android:layout_above="#+id/btnOk" for your webview, and do fill_parent for width and height of the webview.
However, it is important to note, that in 1.5 and below, RelativeLayout views need to be specified in order in your xml to be recognized correctly.. in other words, you have to have your Button first, then the WebView, since the WebView will reference the button. I think this has been changed in 1.6 or 2.0, but I am not positive which.
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Ok"
android:id="#+id/btnOk"
android:layout_width="120px"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<WebView android:id="#+id/webview"
android:layout_above="#+id/btnOk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>

Categories

Resources