How do we get the size of a widget?

NeoTechni

Well-Known Member
Licensed User
Longtime User
I can't assume any values from the layout, or take a guess since difference devices would have different sizes.

There needs to be a way to obtain the size
 

Attachments

  • lcar.jpg
    lcar.jpg
    85.3 KB · Views: 458

gregwa

Member
Licensed User
Longtime User
You have access to the width, height, top and left variables.

B4X:
   Log("Button1 - Width=" & Button1.Width & " Height=" & Button1.Height & " Left=" & Button1.Left & " Top=" & Button1.Top)

Results in:

Button1 - Width=100 Height=90 Left=40 Top=30

This can be done anytime after the activity is loaded.

I can't assume any values from the layout, or take a guess since difference devices would have different sizes.

There needs to be a way to obtain the size
 
Upvote 0

gregwa

Member
Licensed User
Longtime User
Ah. Sorry. Many people refer to views as widgets, so I got confused.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I have it set to resize, and the layout set to fill_parent
I'm told the size for lockscreen widgets changes on each device. It's not a set dip. So I can't assume anything.

There's really no way to get the width/height?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I've just been trying to work this out too, I loaded the layout (hidden) in the activity and measured and stored that. It seems to be the same size if I display it and using it to draw onto a canvas doesn't seem to cause issues.

May not be the same for all devices, I haven't tested that yet. That's next.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hmm, shame. I've just tried it on a couple of devices and it appears OK across resolutions and Dpi's so hopefully it'll be OK for standard widgets.
 
Upvote 0
Top