Android ad size (smart banner not always working) - android

I got a realy annoying Problem with adMob and his banner sizes.
The smart banner size is a realy good thing, it does almost anything for you, what has to do with sizing ads, but only almost..
In the google docs is a table which sizes the smartbanner supports.
There are many sizes supported but not the landscape from a normal android phone..
https://developers.google.com/mobile-ads-sdk/android-legacy/docs/admob/smart-banners
Thats how it looks like now:
Portrait - all good
Landscape - dont work
So is there a way to display my ad in landscape at the right way?
(this is for the ads:adSize="SMART_BANNER", when i use ads:adSize="BANNER" it display on both but its locked to the size that ads:adSize="BANNER" is giving you, so it look terrible on bigger screens)
XML
<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:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/main_bg_color"
android:id="#+id/rel_bg_home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:layout_centerInParent="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="50sp"
android:id="#+id/uber"
android:shadowColor="#000000"
android:shadowRadius="5"
android:textStyle="bold"
android:textColor="#color/text_color"
android:layout_gravity="center_horizontal"
android:layout_weight="0.20"
android:gravity="center|bottom" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|center_horizontal"
android:layout_weight="0.30"
android:gravity="bottom">
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Play"
android:id="#+id/play"
android:textColor="#color/text_color"
android:layout_marginBottom="20dp" />
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Help"
android:id="#+id/help"
android:textColor="#color/text_color"
android:layout_below="#+id/play"
android:layout_marginBottom="20dp" />
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Score"
android:textColor="#color/text_color"
android:id="#+id/score" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_achievement"
android:layout_alignParentLeft="true"
android:layout_alignBottom="#+id/toggle"
android:layout_alignTop="#+id/toggle"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:id="#+id/highscore"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toggle"
android:minHeight="10dp"
android:minWidth="10dp"
android:background="#drawable/check"
android:layout_alignParentRight="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOn=""
android:textOff=""
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_above="#+id/adView" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id1">
</com.google.android.gms.ads.AdView>
</RelativeLayout>

Try to remove any margin or padding attribute from parent view in the xml file.
Hope this help you.

Sometimes smart_banner is not working in landscape mode. So change its size
ads:adSize="BANNER"

Perhaps this open-source solution can help you: https://github.com/ombori/app-banner
either by this:
npm install --save app-banner
var appBanner = require('app-banner');
// - or -
import appBanner from 'app-banner';
appBanner.init({
apple: 'id1234567890',
google: 'com.youcompany.yourapp',
placement: 'bottom-left',
})
or this:
npm install --save app-banner
import AppBanner from 'app-banner/src';
...
<div>
<AppBanner google="com.youcompany.yourapp" apple="id1234567890"
position="bottom-left" />
</div>

Related

can't put a framelayout inside a relativelayout?

So it works fine unless I try to make it fit in the center, then it makes my app crash whenever I run it. I tried changing the framelayout to a linearlayout but it still crashes. Any ideas on how to fix this?
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:layout_alignTop="#+id/current"
android:layout_alignBottom="#+id/current"
android:background="#drawable/wood_background">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recent_notes_list">
</LinearLayout>
</HorizontalScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gen_note"
android:id="#+id/current"
android:singleLine="true"
android:textStyle="bold|italic"
android:typeface="sans"
android:layout_marginLeft="16sp"
android:alpha=".75"
android:gravity="center_vertical|center_horizontal"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
<Button
android:layout_width="35sp"
android:layout_height="match_parent"
android:text="#string/previous_txt"
android:id="#+id/previous"
android:layout_centerVertical="true"
android:layout_alignParentStart="false"
android:layout_below="#+id/horizontalScrollView"
android:textSize="30sp"
android:textStyle="bold"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:alpha=".5" />
<Button
android:layout_width="35sp"
android:layout_height="match_parent"
android:text="#string/next_button"
android:id="#+id/next"
android:layout_centerVertical="true"
android:layout_alignParentStart="false"
android:layout_below="#+id/horizontalScrollView"
android:textSize="30sp"
android:textStyle="bold"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:alpha=".5"
android:singleLine="false"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignStart="#+id/current"
android:layout_marginLeft="20sp"
android:layout_marginRight="33sp"
android:layout_below="#+id/horizontalScrollView"
android:background="#drawable/parchment_back"></LinearLayout>
Project -> Clean
Sometimes it helps
Weird.. I guess it's only crashing if I assign a background image... The funny thing is, this is sorta why I'm using a frame layout anyways (to layer things).. That SORTA fixes my problem I guess.
Nope, never mind. I guess for some reason android doesn't like my parchment texture. I kind of don't need it anyways so I just deleted it.

RelativeLayout displays incorrect on real device

I have a question regarding Android RelativeLayout. My layout works perfectly on the emulator which is configured like a LG Nexus4 (screen, resolution). But if I run the app on my real Nexus4 it has serious errors and I don't know how to fix them.
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainMenuLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/zeekedLogo"
android:contentDescription="#string/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
android:src="#drawable/badge" />
<TextView
android:id="#+id/textButtonPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/menu_play"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textButtonResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textButtonPlay"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/menu_resume"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textLabelLevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/zeekedLogo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="54dp"
android:text="#string/menu_level"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textButtonSound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/zeekedLogo"
android:layout_marginLeft="24dp"
android:text="#string/menu_sound_on"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Here are the screenshots of the same layout:
Emulator:
Nexus 4:
Thanks in advance!
After adding a background color to my relativelayout it worked on my Nexus4. It's all I did ... and I think it's strange. But at the end I'm happy that it works.

Not Enough Space to Show Ads Android Issue

I am trying to show Admob ads in my application and i keep getting the following error "Not Enough space to show ad. Need 480 X 75 pixels but only has 400 X 0 pixels". I am using the below xml.
<LinearLayout
android:id="#+id/lySearch"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/txtSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:hint="Search Cards..."
android:inputType="text" />
<ImageButton
android:id="#+id/btnSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:src="#drawable/action_search"
android:scaleType="centerInside"
style="#android:style/Widget.Holo.Light.Button.Borderless.Small"
/>
</LinearLayout>
<TextView
android:id="#+id/txtCat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lySearch"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="List Of Categories"
android:textColor="#000000"
android:textSize="14dp"
android:textStyle="bold" />
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/txtCat" />
<Button
android:id="#+id/btnAddViewDeck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listView"
android:text="Add/View Decks" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxx"
ads:adSize="SMART_BANNER"
android:layout_below="#+id/btnAddViewDeck"
android:layout_alignParentBottom="true"
/>
I tried experimenting with various different width and height but still the issue persists. Any help would be appreciated.
Your first problem is that you have told listView to consume all the height. You haven;'t shown the layout for the container, but if you switch to LinearLayout then you can change it to consume all remaining space instead:
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
Something has also consumed some of the left and right padding. It's either you unshown RelativeLayout container or is coming from s style. In any case remove the padding or margin.

How to make my layout fit in all screens

I have gone through many relative answers on stockoverflow and link's such as Supporting Different Screens or Screen Compatibility Mode
I have created the following relative layout and I am trying to make it look alike in all android screens.
My images fit perfect for 4.8 inch phones but when I try to use a 2.8 inch display or something like like that, some buttons go on top of others, and they do not shrink.
Does anyone have any suggestion how to improve that?
And preferably without increasing the size of my app.
Thanks in advance!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
tools:context=".MainActivity" >
<ImageButton
android:id="#+id/Switch_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="someMethod"
android:background="#drawable/switch_off"/>
<ImageView
android:id="#+id/warning_shot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/more"
android:onClick="someMethod" />
<ImageView
android:id="#+id/imageViewBatteryState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/Switch_off"
/>
<ImageView
android:id="#+id/sh"
android:layout_width="147dp"
android:layout_height="54dp"
android:layout_below="#+id/Switch_off"
android:layout_centerHorizontal="true"
android:background="#drawable/me"/>
<ImageView
android:id="#+id/sit"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="#+id/Switch_off"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/textViewBatteryInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp"
android:textStyle="bold"
android:typeface="monospace"
android:layout_alignBottom="#+id/sit"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
I will suggest you to use LinearLayout instead of Relativelayout specially for the issue :
My images fit perfect for 4.8 inch phones but when I try to use a 2.8
inch display or something like like that, some buttons go on top of
others, and they do not shrink.
Because When you give orientation to Linearlayout then Its child will never get on top of each other for any resolution or screen size.
And If you give them Weight then Views will be in fix position for Each and Every device.
For example Put below Xml in your project and Check this out in Any resolution, It will give the same Result.
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 3" />
</LinearLayout>
</LinearLayout>

Layout issue during AD load

I have a problem setting up layout.
Before AD is loaded it looks like this:
After AD is loaded, everything goes to it's place. It looks like this ( correct )
Does anybody know how to fix this problem? Not that only looks "ugly" for the time which AD is loading, but AD may never be loaded also, and layout could stay this way (first image )forever.
Any suggestions?
I have this XML layout:
<com.example.touch.TouchImageView android:id="#+id/mytouchview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_above="#+id/relat"
/>
<RelativeLayout
android:id="#id/relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_above="#+id/myAdView"
>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true"
android:background="#null" android:src="#drawable/previous" android:id="#+id/previous"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
android:id="#+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true"
android:background="#null" android:src="#drawable/next" android:id="#+id/next"/>
</RelativeLayout>
<com.csjy.sfwn148282.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="#id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:placementType="interstitial"
ap:banner_type="inappad"
ap:test_mode="true"
ap:canShowMR="false"
android:layout_alignParentBottom="true"
/>
EDIT:
After #Szymon answer layout looks like this. It's okay because it's the same while loading the AD. The problem is that now, buttons are missing..
Change your top level Relative Layout to a linear Layout (vertical) and then use layout_weight on the three layouts. set the layout_weight for mytouchview to 1 and the other two to 0. This will give mytouchview all the extra space and push the buttons and ad to the bottom. When the ad takes up space it will push the button tray up appropriately, but it won't take any space if the ad never loaded.
Try that one:
<?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" xmlns:app="http://schemas.android.com/apk/res/example.com">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#+id/myAdView"
android:orientation="vertical" >
<com.example.touch.TouchImageView android:id="#+id/mytouchview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
/>
<RelativeLayout
android:id="#id/+relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentLeft="true"
android:background="#null" android:src="#drawable/previous" android:id="#+id/previous"/>
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="2/15"
android:id="#+id/memeNumber" android:layout_centerInParent="true" android:layout_margin="5dp"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dp" android:layout_alignParentRight="true"
android:background="#null" android:src="#drawable/next" android:id="#+id/next"/>
</RelativeLayout>
</LinearLayout>
<com.csjy.sfwn148282.AdView
xmlns:ap="http://schemas.android.com/apk/res-auto"
android:id="#id/myAdView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ap:animation="fade"
ap:placementType="interstitial"
ap:banner_type="inappad"
ap:test_mode="true"
ap:canShowMR="false"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>

Categories

Resources