Android Question [Solved] Image was reset while using SetLayoutAnimated

rraswisak

Active Member
Licensed User
Longtime User
Hi All,

I have following code to add and place image to activity
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    Dim xui As XUI
    Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets,"kiwi.png",100dip,100dip,True)
    
    Dim p As B4XView = xui.CreatePanel("")
    Activity.AddView(p,X-50dip, Y-50dip,100dip,100dip)
    p.SetBitmap(bmp)
    Sleep(2000)
    p.SetLayoutAnimated(1000,X-5dip,Y-5dip,10dip,10dip)
End Sub

anigif.gif


How to keep the image reduce in size and keep the ratio while using SetLayoutAnimated ?

Thank you
 

rraswisak

Active Member
Licensed User
Longtime User
I think i can manage this with different approach, for this purpose using ImageView is the solution.

Here is my working code:
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    If Action = Activity.ACTION_DOWN Then
        Dim xui As XUI
        Dim bmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets,"kiwi.png",100dip,100dip,False)
      
        Dim c As ImageView
        c.Initialize("")
        c.SetBackgroundImage(bmp)
        c.Gravity = Gravity.FILL

        Activity.AddView(c,X-50dip, Y-50dip,100dip,100dip)
        Sleep(2000)
        c.SetLayoutAnimated(1000,X-5dip,Y-5dip,10dip,10dip)
    End If
End Sub
 
Upvote 0
Top