ScrollView moved AdMob ads - android

Well before my ads were working fine and were always at the bottom of the screen, but now I added a scrollview and the ads move up a little bit to be right under my scrollbar.
main.xml
<?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"
android:background="#drawable/pattern_carbon_fiber_dark">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content" android:layout_height="339px">
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:text="Silent Mode" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/silent_textview"></TextView>
<ToggleButton android:layout_height="wrap_content" android:text="Silent Mode" android:id="#+id/silentbutton" android:layout_width="wrap_content" android:textOff="OFF" android:textOn="ON"></ToggleButton>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Wifi " android:id="#+id/wifi_textview"></TextView>
<ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:layout_height="wrap_content" android:id="#+id/wifibutton"></ToggleButton>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/gps" android:id="#+id/gps_textview"></TextView>
<Button android:text="#string/gpsbutton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/gps"></Button>
<TextView android:layout_width="wrap_content" android:text="#string/bluetooth" android:layout_height="wrap_content" android:id="#+id/bluetooth_textview"></TextView>
<ToggleButton android:layout_width="wrap_content" android:text="ToggleButton" android:id="#+id/bluetooth" android:layout_height="wrap_content"></ToggleButton>
<TextView android:text="#string/brightness" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/screenbrightness_textview"></TextView>
<SeekBar android:layout_height="wrap_content" android:id="#+id/SbBar" android:layout_width="fill_parent" android:max="255"></SeekBar>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="fill_parent"
ads:adSize="BANNER"
ads:adUnitId="a14ddb1a61b9fb4"
ads:loadAdOnCreate="true"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_height="wrap_content"
android:layout_alignParentTop="false">
</com.google.ads.AdView>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Please help, thanks!
EDIT: Picture
UI pic http://img52.imageshack.us/img52/9397/unledyv.png

1) You will probably leave the ads outside the scollview so they are always visible (as opposed to scroll out of the screen)
2) What is the purpose of the relativelayout surrounding the adview? That is the only view inside it: just remove it and you will get the same layout, but better performance.
Based on the update, I suggest you to try this layout (you will need to fill many blanks):
<RelativeLayout
...
>
<AdView
android:id="#+id/adView"
android:layout_alignParentBottom="true"
...
/>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="#id/adView"
...
>
<LinearLayout
...
>
...
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
The basic idea is to put the AdView ad the bottom of the screen using a RelativeLayout, and then setting the ScollView to be placed above the ads (so it does not block them) and aligned to the top of the screen.

Why don't you try using a relative layout as the root layout.
<RelativeLayout>
<LinearLayout
android:layout_alignParentTop="true">
ETC
</LinearLayout>
<com.google.ads.AdView
android:layout_alignParentBottom="true">
</com.google.ads.AdView>
</RelativeLayout>

To improve the user experience, we can move the ad outside the ScrollView and use a RelativeLayout to pin the ad to the bottom of the screen. This is the needed XML markup:
<?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">
<ScrollView android:id="#+id/scrollLayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="#+id/adView">
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Place very long string here..."/>
</LinearLayout>
</ScrollView>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="INSERT_YOUR_AD_UNIT_ID_HERE"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"/>
</RelativeLayout>

Related

Admob banner adjustment on Android ListView

i have list view and i want to show ad banner in the bottom of this list view and also i have created space for this banner i.e android:paddingBottom="50dp", so i want to show ad on this 50dp space but now my ad showing on the above of this 50dp space i have 1 MainActivity.java and 2 xml file, first is activity_main.xml and second is single_row.xml. We know that there is no need to show java class because we set ad adjustment by xml.So i share my both xmls here and remember that i have relative layout not linear so there is no layout_weight option.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg"
android:paddingBottom="50dp"
tools:context=".MainActivity" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="aaaa111122223333"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</LinearLayout>
</RelativeLayout>
My sigle_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:src="#drawable/img0"
android:paddingBottom="10dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:layout_toLeftOf="#+id/imageView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textStyle="bold"
/>
</RelativeLayout>
You need to set layout_above for the ListView to place above the AdView Layout, so that you can see all the list items
android:layout_above="#+id/layout"
Also, remove the bottom padding from the parent RelativeLayout
android:paddingBottom is used to leave some space at the bottom inside the View not to specify some space for other Views.
Now, remove the following attribute from parent RelativeLayout
android:paddingBottom="50dp"
And set 50dp to android:layout_height attribute for com.google.ads.AdView as below
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="aaaa111122223333"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</LinearLayout>
Use a relative Container, inside that use layout_above="#id/your_adview_id" on your listview.
Add your adView below ListView and set its visibility="gone".
In your java, when the add is loaded, set the visibility to visible as adView.setVisibility(View.VISIBLE);
I hope this helps :)

Android -Ad using Admob for image view

In my andriod app I have an image view and back and next button as shown below. It works fine. Now I want to draw an admob ad below the buttons or above the buttons but below the image. In any case I don’t want image to be cropped by ad or buttons.
Here is layout which have image and two buttons:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/Linear1">
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="#+id/katha_image"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginBottom="#dimen/menu_item_size"></ImageView>
<LinearLayout android:layout_width="fill_parent"
android:orientation="horizontal" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_gravity="bottom|center">
<Button android:id="#+id/Button_Back" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="50"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:text="#string/back"
android:textSize="#dimen/button_size" android:minWidth="75px"></Button>
<Button android:text="#string/next" android:textSize="#dimen/button_size"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="50" android:id="#+id/Button_Next"></Button>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Please suggest.
PC
You'll want to use android:layout_above or android:layout_below with your elements in a RelativeLayout so that they don't overlap.
<com.google.ads.AdView xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_above="#id/linearLayout1"/>
<!-- Assumes your LinearLayout with buttons have id "linearLayout1" -->
Then add android:layout_above="#id/adView" on your ImageView to make it lay out above the ad.

Android webview fullscreen

I have a layout where I need to show a webview on part of the screen. I've set the layout up and in the Graphical Layout in Eclipse, it does look as I want to, like this (logo and heading blacked out):
However when I open this layout in the simulator or on a Phone it shows the WebView as a full screen. How do I make a layout like this? Any help is much appreciated!
Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/Theme.KB_default"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_background_shape" >
<TextView
android:id="#+id/heading"
style="#style/Theme.KB_header"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/app_name" >
</TextView>
<ImageView
android:id="#+id/imageViewPadlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:contentDescription="#string/global_secure_connection"
android:src="#drawable/padlock" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#color/black" >
</View>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.41"
android:orientation="vertical" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:contentDescription="#string/global_logo"
android:scaleType="fitXY"
android:src="#drawable/logo_transparrent_notext" />
</LinearLayout>
</LinearLayout>
make one of table block as webview
check this link
http://developer.android.com/reference/android/widget/TableLayout.html
You can also check this example by using dialog
http://www.41post.com/4673/programming/android-creating-a-webview-dialog
Well I seem to be the stupidist guy alive. My layout worked but I forgot to add " setContentView(xml.file);" so it never loaded the XML... Stupid

Admob below background

http://i.stack.imgur.com/lbs7l.png
I'm trying to setup admob below the background, but I keep getting admob on top of the background like this .
http://i.stack.imgur.com/YJXU2.png
So what happened is I have a button alignedParentBottom="true"
but the ad is keep covering the button.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back"
android:textSize="40sp"
android:layout_alignParentBottom="true"
></Button>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/backButton"
>
<TextView
android:id="#+id/TextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="20sp"
android:text="#string/helphelp"></TextView>
</ScrollView>
<com.google.ads.AdView android:id="#+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"
android:layout_below="#id/backButton"></com.google.ads.AdView>
You can create a second RelativeLayout - the inner one will have all of your main layout content, and the outer one will hold your layout content and the AdView. Simply set the AdView to the bottom, and set your RelativeLayout content above the AdView, and it will force the back button up when the ad comes back.
I have provided the code here for your convenience.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_above="#+id/adView2">
<Button
android:id="#+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back"
android:textSize="40sp"
android:layout_alignParentBottom="true">
</Button>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/backButton">
<TextView
android:id="#+id/TextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="20sp"
android:text="#string/helphelp">
</TextView>
</ScrollView>
</RelativeLayout>
<com.google.ads.AdView android:id="#id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="MY_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true">
</com.google.ads.AdView>
</RelativeLayout>
Side note: Make sure your UI elements aren't too close to the ads; that may encourage accidental clicks, and is against AdMob's ToS.
Use a FrameLayout:
Child views are drawn in a stack, with the most recently added child on top.
There's nothing to it. If you want to ensure that the Button is drawn over the AdView, then place the AdView earlier in a common FrameLayout parent. E.g.,
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView2" ... />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
... Buttons, etc. ...
</RelativeLayout>
</FrameLayout>
Although you may want just the Button and AdView in a FrameLayout child of the RelativeLayout. Or you may want a RelativeLayout parent of the AdView in the example above, to position the ad.

How to place Relative layout at bottom of screen(or linear layout).?

I have following in xml
I wanna put the second linear layout at the bottom of the screen.
How will i do?
I have set the property of second Relative layout to bottom but still not showing at bottom..
**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout android:id="#+id/RelativeLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="bottom">
</RelativeLayout>
</LinearLayout>
**
Thanx in advance
I was searching for this a while too. My just found solution is to use the property:
android:layout_alignParentBottom="true"
instead of your existing android:layout_gravity="bottom"
This unfortunately with my layout only works when having an additional RelativeLayout as root layout and the rest added to it. Maybe this is not always the case, but with having a LinearLayout (even when told to use fill_parent) it only used the height all added elements needed and put my footer at the bottom of those.
I came to this solution, looking at this related question: How do I achieve the following result using RelativeLayout?
EDIT here because format in answer comment got lost:
Do you mean you can't re-write it or that it didn't work?
I had a vertical LinearLayout too and my new xml structure looks (without the layout size params etc.) sth. like this:
<RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout01">
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_below="#+id/RelativeLayout01">
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/RelativeLayout02"
android:layout_alignParentBottom="true">
</RelativeLayout>
</RelativeLayout>
The Layout you want at the bottom should have:
android:gravity = "bottom"
and its parent should have:
android:layout_height="fill_parent"
<Linearlayout android:layout_height="fill_parent"
android:orinationtation="vertical"
android:layout_width="fill_parent">
<RelativeLayout android:layout_height="0dp"
android:layout_width="fill_parent"
android:weight="1">
</RelativeLayout>
<RelativeLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:weight="1"
>
</RelativeLayout>
</Linearlayout >
You should put a View before your last layout with weight 1, and it will put it to bottom. Like this:
<View android:id="#+id/emptySpace"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
Try using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffb3e5fc"
android:id="#+id/linearLayout1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<Button
android:id="#+id/button1"
android:text="Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/centerPoint" />
<TextView
android:id="#+id/centerPoint"
android:text=""
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button2"
android:text="Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/centerPoint" />
</RelativeLayout>
</LinearLayout>
It produces something that looks like this
For my it's work.
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#fff"
android:gravity="bottom"
app:layout_anchor="#+id/fab_inout"
app:layout_anchorGravity="bottom|center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dsfsdfasdf df" />
</RelativeLayout>

Categories

Resources