我想在内部扩展存储NativeAd的视图。代码如下:
public void insert_Native_ad()
{
boolean purchased_noAd = checked_purchase_ad();
if (purchased_noAd)
{
}
else
{
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float deviceWidthInDp = displayMetrics.widthPixels / displayMetrics.density;
int adWidth = (int)(deviceWidthInDp);
final View inflated_item1 = getLayoutInflater().inflate(R.layout.inflated_view_native_ad, null, false);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params1.setMargins(Constants.SCREEN_W/20, 2, 0, 2);
((ViewGroup) ll_content).addView(inflated_item1, params1);
RelativeLayout inflate_view = (RelativeLayout) inflated_item1.findViewById(R.id.inflate_view);
MobileAds.initialize(getApplicationContext(), getString(R.string.app_id));
final NativeExpressAdView mAdView = new NativeExpressAdView(this);
if (mAdView != null) {
// prevents a crash on older devices
mAdView.clearAnimation();
}
mAdView.setAdSize(new AdSize(adWidth, 250)); // AdSize(width, height),
mAdView.setAdUnitId(getString(R.string.app_unitid));
mAdView.setVideoOptions(new VideoOptions.Builder()
.setStartMuted(true)
.build());
// The VideoController can be used to get lifecycle events and info about an ad's video asset.
// One will always be returned by getVideoController, even if the ad has no video asset.
mVideoController = mAdView.getVideoController();
mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
@Override
public void onVideoEnd() {
Log.d(LOG_TAG, "Video playback is finished.");
super.onVideoEnd();
}
});
// Set an AdListener for the AdView, so the Activity can take action when an ad has finished loading.
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if (mVideoController.hasVideoContent()) {
Log.d(LOG_TAG, "Received an ad that contains a video asset.");
} else {
Log.d(LOG_TAG, "Received an ad that does not contain a video asset.");
}
}
});
inflate_view.addView(mAdView);
final AdRequest.Builder adReq = new AdRequest.Builder();
final AdRequest adRequest = adReq.build();
mAdView.loadAd(adRequest);
}
}
视图已成功膨胀,但内部未显示任何广告。有什么问题?