Skip to content

Commit 560115f

Browse files
Merge pull request #139 from MihaiCristianCondrea/codex/add-native-ad-to-about-page
feat: add about page native ad layout
2 parents 6fc315f + b2fd6a7 commit 560115f

File tree

5 files changed

+111
-9
lines changed

5 files changed

+111
-9
lines changed

AGENTS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You are an experienced Android app developer.
1818
- Run `./gradlew test` before committing changes.
1919

2020
## Native ads
21-
- Native ad XML layouts should wrap their content in a `MaterialCardView` with the ID `ad_card` using `@style/Widget.Material3.CardView.Outlined` and appropriate rounded corner overlays.
21+
- Native ad XML layouts should wrap their content in a `MaterialCardView` with the ID `ad_card` using a Material3 card style and appropriate rounded corner overlays.
2222
- Use the shared `@layout/ad_attribution` snippet for displaying the ad attribution text.
23-
- Place the attribution include as the first child of the ad card and override its padding or text color attributes to fit each layout.
23+
- Include the attribution exactly as `<include layout="@layout/ad_attribution" />` with no additional attributes such as padding or margins.
24+
- Position the attribution snippet at the top of the ad card so it appears first in the layout.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content">
6+
7+
<com.google.android.material.card.MaterialCardView
8+
android:id="@+id/ad_card"
9+
style="@style/Widget.Material3.CardView.Elevated"
10+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:layout_marginHorizontal="24dp"
14+
app:cardUseCompatPadding="false"
15+
app:cardPreventCornerOverlap="true">
16+
17+
<LinearLayout
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:orientation="vertical"
21+
android:padding="16dp">
22+
23+
<include layout="@layout/ad_attribution" />
24+
25+
<androidx.constraintlayout.widget.ConstraintLayout
26+
android:id="@+id/ad_host"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
android:layout_marginTop="8dp">
30+
31+
<com.google.android.material.card.MaterialCardView
32+
android:id="@+id/media_card"
33+
android:layout_width="96dp"
34+
android:layout_height="96dp"
35+
app:cardCornerRadius="16dp"
36+
app:cardUseCompatPadding="false"
37+
app:cardPreventCornerOverlap="true"
38+
app:layout_constraintTop_toTopOf="parent"
39+
app:layout_constraintStart_toStartOf="parent">
40+
41+
<com.google.android.gms.ads.nativead.MediaView
42+
android:id="@+id/ad_media"
43+
android:layout_width="match_parent"
44+
android:layout_height="match_parent" />
45+
</com.google.android.material.card.MaterialCardView>
46+
47+
<TextView
48+
android:id="@+id/ad_headline"
49+
android:layout_width="0dp"
50+
android:layout_height="wrap_content"
51+
android:layout_marginStart="12dp"
52+
android:ellipsize="end"
53+
android:maxLines="1"
54+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
55+
app:layout_constraintTop_toTopOf="@id/media_card"
56+
app:layout_constraintStart_toEndOf="@id/media_card"
57+
app:layout_constraintEnd_toEndOf="parent" />
58+
59+
<TextView
60+
android:id="@+id/ad_body"
61+
android:layout_width="0dp"
62+
android:layout_height="wrap_content"
63+
android:ellipsize="end"
64+
android:maxLines="2"
65+
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
66+
app:layout_constraintStart_toStartOf="@id/ad_headline"
67+
app:layout_constraintEnd_toEndOf="@id/ad_headline"
68+
app:layout_constraintTop_toBottomOf="@id/ad_headline" />
69+
70+
<me.zhanghai.android.materialratingbar.MaterialRatingBar
71+
android:id="@+id/ad_stars"
72+
style="@style/Widget.MaterialRatingBar.RatingBar.Small"
73+
android:layout_width="wrap_content"
74+
android:layout_height="wrap_content"
75+
android:isIndicator="true"
76+
android:numStars="5"
77+
android:stepSize="0.5"
78+
app:layout_constraintBottom_toBottomOf="parent"
79+
app:layout_constraintEnd_toStartOf="@id/ad_call_to_action"
80+
app:layout_constraintStart_toStartOf="@id/ad_headline"
81+
app:layout_constraintTop_toBottomOf="@id/ad_body" />
82+
83+
<com.google.android.material.button.MaterialButton
84+
android:id="@+id/ad_call_to_action"
85+
android:layout_width="wrap_content"
86+
android:layout_height="40dp"
87+
android:minWidth="88dp"
88+
android:layout_marginStart="12dp"
89+
android:layout_marginTop="8dp"
90+
android:paddingHorizontal="12dp"
91+
app:layout_constraintEnd_toEndOf="parent"
92+
app:layout_constraintStart_toEndOf="@id/ad_stars"
93+
app:layout_constraintTop_toBottomOf="@id/ad_body"
94+
app:layout_constraintHorizontal_chainStyle="packed" />
95+
96+
</androidx.constraintlayout.widget.ConstraintLayout>
97+
</LinearLayout>
98+
</com.google.android.material.card.MaterialCardView>
99+
</com.google.android.gms.ads.nativead.NativeAdView>
100+

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
5757
android:id="@+id/ad_view"
5858
android:layout_width="match_parent"
59-
android:layout_height="match_parent"
59+
android:layout_height="wrap_content"
6060
app:nativeAdLayout="@layout/bottom_app_bar_native_ad" />
6161
</FrameLayout>
6262

app/src/main/res/layout/bottom_app_bar_native_ad.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
style="@style/Widget.Material3.Button.TextButton"
5757
android:layout_width="wrap_content"
5858
android:layout_height="wrap_content"
59-
android:minWidth="64dp"
60-
android:minHeight="36dp"
59+
android:minWidth="88dp"
60+
android:minHeight="40dp"
6161
android:layout_marginStart="8dp" />
6262
</LinearLayout>
6363
</LinearLayout>

app/src/main/res/layout/fragment_about.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
<com.google.android.material.card.MaterialCardView
1414
android:id="@+id/card_view_about"
1515
style="@style/Widget.Material3.CardView.Elevated"
16+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRounded"
1617
android:layout_width="match_parent"
1718
android:layout_height="wrap_content"
18-
android:layout_margin="24dp"
19-
app:cardCornerRadius="24dp"
19+
android:layout_marginHorizontal="24dp"
20+
android:layout_marginTop="24dp"
2021
app:layout_constraintTop_toTopOf="parent">
2122

2223
<androidx.constraintlayout.widget.ConstraintLayout
@@ -172,9 +173,9 @@
172173
android:id="@+id/ad_view"
173174
android:layout_width="match_parent"
174175
android:layout_height="wrap_content"
175-
android:layout_marginTop="16dp"
176+
android:layout_marginTop="2dp"
176177
app:layout_constraintTop_toBottomOf="@id/card_view_about"
177-
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
178+
app:nativeAdLayout="@layout/about_native_ad" />
178179

179180
<com.airbnb.lottie.LottieAnimationView
180181
android:id="@+id/animation_about"

0 commit comments

Comments
 (0)