Banner doesnt show on the screen only graph - android

I have one problem if i use this code i cant see google AdView i dont know where is it :( Whatever i make it wasnt show but the banner in first page working good but this in second not :( Can anyoune suggest me
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id" />
<com.calculator.grap.GraphPanel
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>

As it is a vertical layout it show on the top.Moreover you should not be using match_parent for both width and height of AdView.
You should use height as 0dp if you are using layout_weight.
Change the height of GraphPanel to 0dp.
Also rephrase your question in a better way.

Related

AdMob banner at bottom - Converting Linearlayout to RelativeLayout

I am pretty new to android. I am trying to add an admob banner at the bottom of an app, actually in two of the activities. I think Linearlayout is not the right way of doing it.
So please help me Convert Linearlayout to RelativeLayout.
Also while running the app, only the activity_entry.xml sample-google-banner shows up. The view_home.xml banner just shows up static white space.
And how do I make the banner smart? I mean I want it to show up only when theres a banner to be displayed, and not as a static blank space.
activity_entry.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/view_toolbar"/>
<fragment
android:id="#+id/entry_fragment"
class="net.etuldan.sparss.fragment.EntryFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>
view_home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:showIn="#layout/activity_home"
android:weightSum="1">
<include layout="#layout/view_toolbar"/>
<fragment
android:id="#+id/entries_list_fragment"
android:name="net.etuldan.sparss.fragment.EntriesListFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>
Here are some tips for getting what you want:
look here for making it into relativelayout: adMob | Smart banner at bottom?
basically, the key code is that you should have
android:layout_alignParentBottom="true"
You can nest your layout if it helps... or not.
Second part: consider using adListener and use onReceiveAd() and onFailedToReceiveAd() to dynamically format your layout.
Look here for some points on adListener:
How to know if AdMob ad has been loaded

AdMob ads taking up all screen space

After long hours of problems with getting ads to work it finally works.
But now my AdMob ads add a black background in its view/layout(I don't know)
So my game isn't visible anymore. The size of the ad itself is exactly how I want it,
but I need to get rid of this weird black background.
I suspect that I'm doing something wrong with layouts:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-4118138803752321/8641047294"
android:orientation="vertical" />
</RelativeLayout>
What exactly is going wrong?
Because it's a RelativeLayout please assign the position of the AdView and that should take care of your issue.
Specify the position for your Adview within the RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-4118138803752321/8641047294"
/>
</RelativeLayout>

Android Scroll view content

Hi I want to draw my ScrollView on whole screen and ScrollView content should be display on the whole screen
But I also want to show my ad on bottom of the screen. I have confusion here I just want to give ScrollView a
Height something like (Fill parent - 20 px) and my ads should be display at (20 PX) at the bottom of the screen
Note that whatever in the scroll view it should be display on whole screen except (20 px ) of the bottom.
You can try this:
<?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"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="20dip"
android:id="#+id/adView"
android:layout_alignParentBottom="true"
>
</LinearLayout>
<ScrollView
android:layout_alignTop="#id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Page content -->
</ScrollView>
</RelativeLayout>
So adView will take fixed 20 dip portion and remaining part will be taken by ScrollView.
Hope this helps.
use this layout:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="#+id/your_ad_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="sample button" />
</LinearLayout>
<ScrollView
android:id="#+id/myscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/your_ad_layout"
>
</>
</RelativeLayout>
All 3 current answers use a RelativeLayout as the root element of the layout, this is bad for performance.
Use a FrameLayout instead, then to make your ScrollView fill_parent - 20px, set its height to fill_parent and its layout_marginBottom to 20px. Set the Ad View to layout_gravity="bottom" and its height to 20px.
In addition, you should make this 20px 20dp, move it into a values/dimens.xml file, and use this same value for the two parameter mentioned above. It's then easy to define different sizes per screen size/density.
// try this
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ScrollView>
<com.google.ads.AdView
android:id="#+id/adView1"
android:layout_width="match_parent"
android:layout_height="20dp"
app:adSize="SMART_BANNER"
app:adUnitId="ca-app-pub-9766031373541061/3761995838"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" >
</com.google.ads.AdView>
</LinearLayout>

Android: admob ad at wrong place

I am trying to position my ad banner at bottom of the screen. However, part of the ad is appearing at the top and other part at the bottom. Please take a look at the image below
wrong ad http://img513.imageshack.us/img513/4390/shot000025.png
Below is the code if that helps,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/maingradient"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativelayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/relativeLayout1" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:divider="#00ff00"
android:fastScrollEnabled="true"
android:focusable="false"
android:listSelector="#000000"
android:paddingTop="5dp"
android:saveEnabled="true" >
</ListView>
</RelativeLayout>
<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:adSize="SMART_BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="a14fd64cddd4168"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Can someone help please?
Thx!
Rahul.
Not sure what your exact problem is, but I see a few issues with your layout. First, you have a RelativeLayout nested inside another RelativeLayout, but are trying to place it below a third relative layout not contained in the parent? Also, the root RelativeLayout in your file has the android:orientation attribute, which is for LinearLayouts. It's all a bit confusing.
As for a solution, try making the root RelativeLayout a LinearLayout and keeping the vertical orientation. You can give your nested RelativeLayout a android:layout_height of 0dip and android:layout_weight of 1 (and get rid of the layout_below attribute, I'm not sure why it's there). This will put your ListView above the ad, and cause it to fill all the space not taken up by the Ad. Hope this helps.
try the following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black" >
<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="50dp"
ads:adSize="SMART_BANNER"
android:layout_alignParentBottom="true"
ads:adUnitId="a14fd64cddd4168"
ads:loadAdOnCreate="true" />
<ListView
android:id="#+id/show_locations_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/black"
android:layout_above="#+id/adView"
android:scrollbars="none"
android:scrollingCache="false" >
</ListView>
Hope it helps

ListView taking up all space, when trying to use an Admob Adview in Android

I am trying to get Google Admob advertisements to display on the main screen of an app that consists of a ListView. Unfortunately, the ListView is taking up all of the space on the screen, and then the advertisement appears over the top of it. I have tried putting the ListView at the top, followed by an AdView, and I've also tried putting the AdView at the top, followed by the ListView, but nothing works.
If I set the size of the LinearLayout enclosing the ListView to a fixed height (eg, 200px) then it it limits the size and fixes the problem, but I don't want to do this, because screen heights of Android devices vary so much. Is there no way to tell the ListView to not take up all the space without setting a fixed size?
My code is below, I'd be grateful for any help:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_alignParentTop="true"
android:id="#+id/ad_layout"
android:orientation="vertical"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentBottom="true"
android:layout_below="#+id/ad_layout"
android:orientation="vertical"
android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no_hosts"/>
</LinearLayout>
</RelativeLayout>
Both of your LinearLayouts have height of fill_parent. That means that they'll both be the full height of their parent. Clearly not what you want. Try this:
<?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">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no_hosts"/>
</LinearLayout>
You have a relative layout. you need to set the listview property to layout_below="yourAdLayout" or rename the parent layout to linear layout. the orientation flag is not used in a relative layout, only in linear.

Categories

Resources