Android Banner Ads how to resize

284 views Asked by At

In my android app i already load a Ad from DFP, in this case with custom size 125*125) and display it correctly.

AdSize customAdSize = new AdSize(DFP_SPOT_DIM, DFP_SPOT_DIM);
float density = context.getResources().getDisplayMetrics().density;
int height = Math.round(DFP_SPOT_DIM * density);
adView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, height));
adView.setAdSizes(customAdSize);

What I would like to do is, reuse that same ad and change is size, lets say that i want to display it using a square of 56*56. The problem is that scale and setting a new layout size makes the 125*125 appear inside a scrollable view. what i would like is for the ad to be resized to that size.

float density = context.getResources().getDisplayMetrics().density;
int heightSp = Math.round(height * density);
adView.setAdSizes(new AdSize(height,height));
ViewGroup.LayoutParams params = adView.getLayoutParams();
params.height = heightSp;
adView.requestLayout();

this will put the view in the correct size however the ad inside will be of 125*125 and the view is scrollable. it does not scale..

0

There are 0 answers