googleads / googleads-mobile-android-native-templates

Apache License 2.0
116 stars 102 forks source link

Request: allow to set template type during runtime #41

Open AndroidDeveloperLB opened 1 year ago

AndroidDeveloperLB commented 1 year ago

Currently it's available only in layout XML file...

https://developers.google.com/admob/android/native/templates

<com.google.android.ads.nativetemplates.TemplateView...
   app:gnt_template_type="@layout/gnt_small_template_view" ... />

...
NVentimiglia commented 1 year ago

Hi @AndroidDeveloperLB

Can you expand further on what you are wanting and your specific use case? Are you asking to construct the template view in code without a xml file ?

AndroidDeveloperLB commented 1 year ago

@NVentimiglia Sometimes you load an ad that has media, and sometimes you don't. For example, if you fail to load an ad that has media, you might want to have a fallback to load an ad that doesn't. Once you have the ad, you will choose which template type to use here. But currently this is only possible via layout XML and not via Java/Kotlin.

NVentimiglia commented 1 year ago

@AndroidDeveloperLB

Got it, you would like to define the view in pure Java / Kotlin without the XML file. I will bring this us as a needed enhancement.

AndroidDeveloperLB commented 1 year ago

@NVentimiglia It's not necessary without XML, just the part of the "gnt_template_type" , to be set in Java/Kotlin. Of course, if there are more things that are only in XML, please consider having them in Java/Kotlin, as well

JillSong commented 10 months ago

Request recorded. Closing the issue.

AndroidDeveloperLB commented 10 months ago

@JillSong Why close? This means it's now possible?

ericleich commented 9 months ago

@AndroidDeveloperLB from https://support.google.com/admob/answer/6240809, the primary image (media view asset) is guaranteed to be returned. It just may not always have video. Are you saying that if the video is not returned, you don't want to render the primary image?

The way it's defined, it's expected that you know the size of ad you want to render (that is, you know the space made available from your app) at request time.

ericleich commented 9 months ago

Maybe I misunderstood. Are you ok with specifying it at request time, you just want to be able to do it through code?

AndroidDeveloperLB commented 9 months ago

@ericleich What video/image? Yes, the request is about the template. That we won't be forced to use as XML, and that we could use code instead, during runtime.

ericleich commented 9 months ago

Nevermind, My initial question didn't make sense.

Agree with the use case: "I want to create a TemplateView and add it to my view hierarchy programmatically." This would require some API to be able to pass the template type.