Page Summary
-
Native Templates provide code-complete views for native ads, enabling fast implementation and easy modification to seamlessly integrate ads into your app's design.
-
There are two template sizes available, small and medium, both using the
TemplateViewclass and scaling to fill the width of their parent views. -
Installing the templates involves downloading the module from GitHub and importing it into your Android Studio project.
-
Using the templates requires including the template in your layout XML and then setting the loaded native ad on the template view.
-
You can style the templates using either traditional layout XML or the
NativeTemplateStyle.Builderobject, which offers various customization options for text and background elements.
Using native ads you can customize your ads resulting in a better user
experience. Better user experiences can increase engagement and improve your
overall yield.
In order to get the most out of native ads, it's important to style your ad layouts so that they feel like a natural extension of your app. To help you get started, we've created Native Templates.
Native Templates are code-complete views for your native ads, designed for fast implementation and easy modification. With Native Templates, you can implement your first native ad in just a few minutes, and you can quickly customize the look and feel without a lot of code. You can place these templates anywhere you want, such as in a recycler view used in a news feed, in a dialog, or anywhere else in your app.
Our native templates are provided as an Android Studio module, so it's easy to include them in your project and use them however you like.
Template sizes
There are two templates: small and medium. They both use the TemplateView
class and both have a fixed aspect ratio. They will scale to fill the width of
their parent views.
Small template
@layout/gnt_small_template_view
The small template is ideal for recycler views, or any time you need a long rectangular ad view. For instance you could use it for in-feed ads.

Medium template
@layout/gnt_medium_template_view
The medium template is meant to be a one-half to three-quarter page view but can also be used in feeds. It is good for landing pages or splash pages.
Feel free to experiment with placement. Of course, you can also change the source code and XML files to suit your requirements.

Installing the native ad templates
To install the native templates, simply download the zip file (using the Clone or download option on GitHub) and import the module into your existing Android Studio project.
Choose File > New > Import Module.
Select the
nativetemplatesfolder.
Add the following line to your app-level
build.gradlefile:dependencies { ... implementation project(':nativetemplates') ... }
Using the native ad templates
You can use the template in any layout XML file, like any other view group.

Using the templates is a two-step process:
First, you need to include the template as part of your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" tools:showIn="@layout/activity_main" > <!-- This is your template view --> <com.google.android.ads.nativetemplates.TemplateView android:id="@+id/my_template" <!-- this attribute determines which template is used. The other option is @layout/gnt_medium_template_view --> app:gnt_template_type="@layout/gnt_small_template_view" android:layout_width="match_parent" android:layout_height="match_parent" />