原生广告会缩减。这是我用于呈现原生广告的代码和布局:
private NativeAdService(Context context) {
moPubNative = new MoPubNative(context.getApplicationContext(), "XXX", new MoPubNative.MoPubNativeNetworkListener() {
@Override
public void onNativeLoad(NativeAd nativeAd) {
NativeAdService.this.nativeAd = nativeAd;
}
@Override
public void onNativeFail(NativeErrorCode errorCode) {
}
});
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_layout)
.iconImageId(R.id.native_ad_icon_image)
.titleId(R.id.native_ad_title)
.textId(R.id.native_ad_text)
.build();
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
moPubNative.makeRequest();
}
这就是我如何呈现广告:
View view = nativeAd.createAdView(context, null);
nativeAd.renderAdView(view);
return view;
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginRight="8dp"
android:background="@color/colorBlueText">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@color/colorBlackText">
<ImageView
android:id="@+id/native_ad_icon_image"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/native_ad_title"
android:layout_width="2dp"
android:layout_height="29dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="8dp"
android:text="Title" />
<TextView
android:id="@+id/native_ad_text"
android:layout_width="20dp"
android:layout_height="49dp"
android:layout_marginBottom="-1dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="8dp"
android:text="AdText" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
这就是我得到的:不知怎样,match_parent值根本不起作用。