Android Question How to fit image to view using this code?

asales

Expert
Licensed User
Longtime User
I'm using this code to create a native ad:
B4X:
    Dim images As List = NativeUnifiedAd.RunMethod("getImages", Null)
    If images.IsInitialized And images.Size > 0 Then
        Dim imgView As Panel = pAdmob.GetView(5)  'example
        Dim image As JavaObject = images.Get(0)
        imgView.Background = image.RunMethod("getDrawable", Null)
        NativeUnifiedAdView.RunMethod("setImageView", Array(imgView))
    End If
I get his result:
tela_nativo4_350.png


How I can fit the image instead fill (without distortion)?

I saw this thread, but I don't know how to use it in this code:

Thanks in advance for any tip.
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
I have no experience with the Google adds. The RunMethod indicate that a jump is made to the google Java code class. As far as I can understand for the Google Class information it must be something like the following steps:

First, the referred B4J example is a B4X code. That means that it should work in B4A also. So add the both the Sub routines FillImageToView and the FitImageToView and add the following globals to your code:
B4X:
   Private xui As XUI '<------------- Add the XUI library
   Private ImgView As ImageView '

One of the two B4X sub routines replace the code:
B4X:
        Dim image As JavaObject = images.Get(0)
        imgView.Background = image.RunMethod("getDrawable", Null)
        NativeUnifiedAdView.RunMethod("setImageView", Array(imgView))
by:
B4X:
        Dim bmp As B4XBitmap = xui.LoadBitmap(images.Get(0))
        imgView.Background = FillImageToView(bmp, imgView.Background )   ' or FitImageToView

Hopes it helps you to a solution.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I have no experience with the Google adds.
(...)
Hopes it helps you to a solution.
Thanks, but it don't give me a solution.

In the guideline polices of Admod I can't use ImageView to renderize main resource (video/image) of the Ad. I can use ImageView only to logo or app icon.

In the panel of this code I can put the MediaView (image or view) and this is the problem:
- How I can fit the image in panel (video resources is fit automatically).
 
Upvote 0
Top