Mehmet Peker
02/21/2022, 2:02 AMAdam Powell
02/21/2022, 2:36 AMAndroidView
composable is likely what you wantMehmet Peker
02/21/2022, 2:49 AMAdam Powell
02/21/2022, 3:10 AMMehmet Peker
02/21/2022, 3:24 AMprivate fun populateTemplateView(nativeAd: NativeAd) = TemplateView(context).apply {
val cd = ColorDrawable(resources.getColor(R.color.white))
val styles =
NativeTemplateStyle.Builder().withMainBackgroundColor(cd).build()
val layout = View.inflate(context,R.layout.native_ad_layout,null)
val template: TemplateView = layout.findViewById(R.id.my_template)
template.setStyles(styles)
template.setNativeAd(nativeAd)
}
Paul Woitaschek
02/21/2022, 5:59 AMMehmet Peker
02/21/2022, 4:50 PMAdam Powell
02/21/2022, 6:40 PMMehmet Peker
02/21/2022, 6:56 PMif(nativeAdLoaded){
AndroidView(factory = {
naviteAdProvider.getTemplateView()
})
}
I think problem is not related with this.I think my problem on populate view function.I dont know maybe i cant inflate template view.I need to help with thisAdam Powell
02/21/2022, 11:08 PMNativeAdProvider
class as posted is returning template
instead of layout
. template
is attached to a parent view already, as the exception message describes; it's a sub-view of the inflated layout. You likely want to return the whole inflated layout root. The caching of that view that this class is performing may also lead to further issues of this sort.Mehmet Peker
02/22/2022, 12:57 AMThank you very much for all your help and effort. Thanks to you, I solved a problem, but I couldn't succeed again. I found that the problem was in a very different place. As soon as I changed the template type, my problem was fixed. I changed the template type from small to medium and my problem was solved.
<com.google.android.ads.nativetemplates.TemplateView
android:id="@+id/my_template"
app:gnt_template_type="@layout/gnt_small_template_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
to
<com.google.android.ads.nativetemplates.TemplateView
android:id="@+id/my_template"
app:gnt_template_type="@layout/gnt_medium_template_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
then problem fixed.