Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.android.gms.ads.AdLoader;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.nativead.AdChoicesView;
import com.google.android.gms.ads.nativead.MediaView;
import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdView;
Expand Down Expand Up @@ -84,6 +85,7 @@ private static void populateNativeAdView(@NonNull NativeAd nativeAd, @NonNull Na
Button callToActionView = adView.findViewById(R.id.ad_call_to_action);
ImageView iconView = adView.findViewById(R.id.ad_app_icon);
TextView attributionView = adView.findViewById(R.id.ad_attribution);
AdChoicesView adChoicesView = adView.findViewById(R.id.ad_choices);

if (mediaView != null) {
adView.setMediaView(mediaView);
Expand All @@ -95,6 +97,9 @@ private static void populateNativeAdView(@NonNull NativeAd nativeAd, @NonNull Na
adView.setIconView(iconView);
}
adView.setAdvertiserView(attributionView);
if (adChoicesView != null) {
adView.setAdChoicesView(adChoicesView);
}

if (headlineView != null) {
headlineView.setText(nativeAd.getHeadline());
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/ad_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
android:layout_height="match_parent" />
</com.google.android.material.card.MaterialCardView>

<com.google.android.gms.ads.nativead.AdChoicesView
android:id="@+id/ad_choices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/ad_headline"
android:layout_width="0dp"
Comment on lines 55 to 57

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Reserve space for the AdChoices icon

The newly added AdChoicesView is anchored to the top-right of the constraint layout, but ad_headline still stretches all the way to parent (app:layout_constraintEnd_toEndOf="parent"). With no constraint or margin between these two views the headline text will occupy the same space as the AdChoices icon, so whichever view is drawn last will obscure the other. AdChoices must remain visible for policy compliance, so the headline should constrain to the start of @id/ad_choices (or similar) to avoid overlap.

Useful? React with 👍 / 👎.

Expand Down