I'm having a problem with my Native Ad. The ad will appear if I specify the ad to be 320x80. But I need the width to be different for different devices so I am trying this:
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_gravity="center_horizontal"
android:visibility="visible"
ads:adUnitId="ca-app-pub-3940256099942544/2793859312"
ads:adSize="FULLWIDTHx80"></com.google.android.gms.ads.NativeExpressAdView>
This doesn't work and when I use wrap_content it just doesn't show the AD.
So I've tried this :
// find out the width of the device in dp
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float deviceWidthInDp = displayMetrics.widthPixels / displayMetrics.density;
int adWidth = (int)(deviceWidthInDp);
adView = new NativeExpressAdView(context);
adView.setAdUnitId("ca-app-pub-3940256099942544/2793859312");
adView.setAdSize(new AdSize(adWidth, 80));
This also does not display the Ad.
Logcat is showing:
Not enough space to load AD needs to be 360x80dp but only has 319x80dp.
Any ideas?