B4J Question how to center image in label?

techknight

Well-Known Member
Licensed User
Longtime User
I have a label with a background image, in the designer I can say Gravity, Center. and that works fine.

But the minute I change the image file in code, it tries to fill the whole label. I dont know how to set it back to center and search isnt telling me anything.

any ideas?
 

stevel05

Expert
Licensed User
Longtime User
I haven't tried it myself but try :
B4X:
Dim LJO as JavaObject = Label1
LJO.Runmethod("setContentDisplay",Array("CENTER"))

Where content display could be one of:

BOTTOM, CENTER, GRAPHIC_ONLY, LEFT, RIGHT, TEXT_ONLY, TOP
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
How are you setting the new image?

If you are using CSSUtils you can do something like this:

B4X:
CSSUtils.SetBackgroundImage(Label1,File.DirAssets,"PO.png")
CSSUtils.SetStyleProperty(Label1,"-fx-background-size","25%")
 
Upvote 0
Top