B4J Question [Resolved]The B4J ImageView image is not displayed at the set size

byz

Active Member
Licensed User
Hello friends of the community. Please help me. In B4A, the image will be displayed at the set size, but in B4J I have tested many ways and the image will not be displayed at the set size. Inside the attachment is a small example.
void:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane1 As Pane
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim pn As Pane
    pn.Initialize("")
    pn.LoadLayout("ly1")
    Dim Thumb As ImageView=pn.GetNode(0)
    Thumb.SetImage(xui.LoadBitmap(File.DirAssets,"girl.jpg"))
    'Thumb.SetImage(xui.LoadBitmapResize(File.DirAssets,"girl.jpg",400,400,True))  'void

    Thumb.Left=50 'void
    Thumb.Top=50 'void
    Thumb.SetSize(400,400) 'void
    pn.GetNode(0).PrefWidth=400 'void
    pn.GetNode(0).PrefHeight=400 'void
    Thumb.Width=400 'void
    Thumb.Height=400 'void
    CSSUtils.SetStyleProperty(Thumb,"-fx-pref-width","400") 'void
    CSSUtils.SetStyleProperty(Thumb,"-fx-pref-height","400") 'void

    Pane1.AddNode(pn,0,0,400,400)
End Sub
 

Attachments

  • ImageSize.zip
    49.1 KB · Views: 7
Last edited:
Solution
Thanks for the reminder @aeric , I shouldn't load the layout file in b4j, but just use the AddNode method.
right code:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim pn As Pane
    pn.Initialize("")

    Dim Thumb As ImageView
    Thumb.Initialize("")
    Thumb.SetImage(xui.LoadBitmap(File.DirAssets,"girl.jpg"))
    pn.AddNode(Thumb,50,50,100,100)

    Pane1.AddNode(pn,0,0,400,400)
End Sub

byz

Active Member
Licensed User
Thanks for the reminder @aeric , I shouldn't load the layout file in b4j, but just use the AddNode method.
right code:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim pn As Pane
    pn.Initialize("")

    Dim Thumb As ImageView
    Thumb.Initialize("")
    Thumb.SetImage(xui.LoadBitmap(File.DirAssets,"girl.jpg"))
    pn.AddNode(Thumb,50,50,100,100)

    Pane1.AddNode(pn,0,0,400,400)
End Sub
 
Last edited:
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…