I use this code to set a image in native ad advanced.
B4X:
Dim images As List = NativeContentAd.RunMethod("getImages", Null)
If images.IsInitialized And images.Size > 0 Then
Dim image As JavaObject = images.Get(0)
logoView.Background = image.RunMethod("getDrawable", Null)
NativeContentAdView.RunMethod("setImageView", Array(logoView))
End If
The logoView is a panel and the background is set to FILL automatically. This is the result.:
How I can set the BitmapDrawable with gravity = CENTER ?
Gravity exists on ImageView methods. so this should work :
B4X:
Dim images As List = NativeContentAd.RunMethod("getImages", Null)
If images.IsInitialized And images.Size > 0 Then
Dim image As JavaObject = images.Get(0)
logoView.Background = image.RunMethod("getDrawable", Null)
logoView.Gravity = Gravity.CENTER
NativeContentAdView.RunMethod("setImageView", Array(logoView))
End If
I found a workaround, using this code snippet.
I don't know If is the best approach, but solved the problem.
B4X:
Dim logoView As B4XView = pAdmob2.GetView(5)
Dim image As JavaObject = images.Get(0)
Dim bd As BitmapDrawable
bd = image.RunMethod("getDrawable", Null)
FitImageToView(bd.Bitmap, logoView)