android MoPub ad align - android

hello how to show mopub ad at the bottom?
I have this code
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mopView = new MoPubView(this);
mopView.setAdUnitId(PUB_ID_320x50);
mopView.setLayoutParams(params);
mopView.loadAd();
mainRelative.addView(mopView, params);
but it show in center of screen , how to align to bottom?
p.s. my main layout is RelativeLayout

//change your layout height to ill parent
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);

Related

How to move burstly ads to the center of the screen in android?

The MainActivity is extending UnityPlayerActivity.
We are using the following code snippet to place banner ads on android.
FrameLayout layout1 = new FrameLayout(this);
BurstlyAnimatedBanner levelUpBanner = new BurstlyAnimatedBanner( this, layout1, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT), "0455184989016204562", "Level_Up_Screen", 30, false);
LayoutParams lp1 = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
addContentView(layout1,lp1);
Doing this is showing the ads at the top-left corner of the screen. I need the ads at the top-center of the screen. I tried using layout1.setForegroundGravity(Gravity.CENTER); but that did not help. How can I achieve what I need? Also, I need to do this programatically and cannot use and xml.
I'm the developer of the Burstly Unity plugin at github.com/Burstly/BurstlyUnityPlugin.
You can center the banner ad by adding it to a RelativeLayout instead of a FrameLayout as we do in the plugin:
mBaseLayout = new RelativeLayout(mActivity);
mBaseLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
mActivity.addContentView(mBaseLayout, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.topMargin = (int)originY;
lp.leftMargin = (int)originX;
burstlyView.setLayoutParams(lp);
mBaseLayout.addView(burstlyView);
With this, you can then position the banner at will. If you wish to position it at the top center, then you'd want to change lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT) to lp.addRule(RelativeLayout.CENTER_HORIZONTAL).

Banner ad not occupying full width

i am able to center my banner using gravity class, but i am not able to stretch my banner to occupy full width.
And also i tried smart_banner which supposed to fill according to the density, but with no success.
need help
RelativeLayout layout = (RelativeLayout)findViewById(R.id.ultimaterellayout);
// Create the adView
AdView adView = new AdView(MainActivity.this, AdSize.BANNER, "aaa324dsfdfsd");
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
layout.addView(adView, layoutParams);
layout.invalidate();
// layout.addView(adView);
adView.loadAd(adRequest);
Try to set the width of RelativeLayout as fill_parent.
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

show admob ads at the bottom of the RelativeLayout using java no XML

I have designed a game with no xml layouts.I have used my own view extending the SurfaceView class .This is the code i am using.
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_ad=new AdView(this,AdSize.BANNER,"################");
rl.addView(myView);
rl.addView(_ad);
_ad.loadAd(new AdRequest());
setContentView(rl);
myView is the instance of class extending SurfaceView
and
_ad is the AdView instance.
I want to show the the ads at the bottom of the screen.But they are getting displayed only at the top.
Please suggest me what to do.I will be very grateful.
The only mistake I was doing was not associating my LayoutParams lay variable with the _ad AdView instance.So here is the code after modification.
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_ad=new AdView(this,AdSize.BANNER,"################");
rl.addView(myView);
rl.addView(_ad,lay); //line which was changed.Everything else was correct
_ad.loadAd(new AdRequest());
setContentView(rl);
Thank You StackOverflow.

Set ScrollView + Fixed Button Programatically on Android with setText.

I' m at this point stuck : I want to have a scrollview + a fixed button at the bottom, but Programatically Way ! I can' t go with XML for some technical reason.
Actually i have this :
//Is it really usefull Relative View?
RelativeLayout layout = new RelativeLayout(this);
ScrollView sv = new ScrollView(this);
sv.setId(2);
// What is it? RelativeLayout.LayoutParams?
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, sv.getId());
sv.setLayoutParams(new ViewGroup.LayoutParams(480, 800));
layout.addView(saveButton, lp);
layout.addView(sv);
I do the first 3 page Google on "fixed button and scrollview Android programatically"
Im beginner on Android, so, don' t hesitate to comment on my code some hints ;)
Thx for your help.
try this
LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(lp);
ScrollView scroll = new ScrollView(this);
LinearLayout.LayoutParams slp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,0, 1.0f);
scroll.setLayoutParams(slp);
Button btn = new Button(this);
ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
btn.setLayoutParams(blp);
btn.setText("Click Me");
layout.addView(scroll);
layout.addView(btn);
setContentView(layout);
If you are trying to create a view where the upper portion of the screen is a scrolling list, and the bottom portion is a button, put the scrollview inside a linearlayout, and put the button in the linearlayout below the scrollview.
http://developer.android.com/reference/android/widget/LinearLayout.html

Center MoPub baner on SurfaceView

I'd like add MoPub ad in my Android game. Game is created on SurfaceView Class. I have no xml layout file. The problem is that I can't center ad on screen. I try center and gravity everything. Still doesn't work. MoPubView extends FrameLayout.
MoPubView mAdView = new MoPubView(this);
mAdView.setAdUnitId("_MY__ID_");
mAdView.loadAd();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
RelativeLayout mRelativeLayout = new RelativeLayout(this);
mRelativeLayout.setGravity(Gravity.CENTER_HORIZONTAL);
mRelativeLayout.addView(mSurface);
mRelativeLayout.addView(mAdView, layoutParams);
mRelativeLayout.invalidate();
setContentView(mRelativeLayout);
Please advise me something because it drawing me crazy. I feel I'm missing something easy.
You can't center the content directly in MoPub, or at least I haven't found a way to do so. It's based on FrameLayout.
You have to center the ad in HTML. If you are using custom HTML code inside your MoPub campaign, just wrap the code inside <div style="text-align:center">...</div>. (Do this through the MoPub administration web). It solved my problem, I was using an OpenX ad provider.
Just create a container layout with "FILL_PARENT" parameters and add your ad view into it like this:
MoPubView mAdView = new MoPubView(this);
mAdView.setAdUnitId(XXXXXXX);
RelativeLayout adContainer = new RelativeLayout(this);
addContentView(adContainer, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
LayoutParams adParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1); //to align vertically at top
adParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1); //to align horizontally at center
adContainer.addView(mAdView, adParams);
mAdView.loadAd();
I know it is not good idea to set constant banner width but as long as your banners are 320px it works fine:
final float scale = getResources().getDisplayMetrics().density;
MoPubView mAdView = new MoPubView(this);
mAdView.setAdUnitId(MOPUB_ID);
mAdView.loadAd();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) (320*scale), LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
RelativeLayout mRelativeLayout = new RelativeLayout(this);
mRelativeLayout.addView(mSurface);
mRelativeLayout.addView(mAdView, layoutParams);
mRelativeLayout.invalidate();
setContentView(mRelativeLayout);
I have done same thing with below code snippet.I am using LibGDX java game engine.
Relativelayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
moPubView = new MoPubView(mActivity.getApplicationContext());
moPubView.setAdUnitId("XXXXXX");// Banner test Ad unit Id.
moPubView.setAutorefreshEnabled(true);
moPubView.setVisibility(View.GONE);
layout.addView(moPubView,adParams);
1.I have Relative layout in parent.
2.Added MoPubView in the parent Relative layout with layoutParams only ALIGN_PARENT_BOTTOM && CENTER_HORIZONTAL
layout.addView(moPubView,adParams);

Categories

Resources