Center and size of widget on screen

HappyDad

Member
Licensed User
Longtime User
Hi, I have made a widget.
It runs fine.
And it looks fine on my AVD emulator.
It occupies 4 x 2 cells.
But when I install it to my phonem, it's smaller.
In the widget list page, it is still labeled 4 x 2.
But when I drag it to home screen,
it is smaller than other widgets which have 4 cells horizontally,
and it is aligned to the left of the screen.
Other 4 cells widgets occupies almost the horizontal size of the screen.

Could you please tell me what the problem is.
My cell phone's screen resolution is 720x1280.
In B4A, I set the panel of the widget to 300 x 144,
and 10 from top and 10 from left.
Once I tried setting the widget width to 310,
but after installing to AVD, the widget didn't show up in the widget list.
 

HappyDad

Member
Licensed User
Longtime User
BTW, I am using the default layout variant of 320*480 in the designer.
I don't know whether this matters.
 
Upvote 0

HappyDad

Member
Licensed User
Longtime User
Hi, I am posting a screenshot, in the attached image.
I shrank the image size to make it smaller.
It was 720 pixels in width before.
The screen size of the phone is 720x1280.
You can see three widgets there.
The lowest one is the one I made, it is a 4 x 2 widget, but it aligns to the left of the screen.
The middle one is a standard 4 x 1 widget. It occupies the whole horizontal screen width.
The top one is the quote widget from Erel's widget tutorial II:
http://www.b4x.com/forum/basic4andr...oid-home-screen-widgets-tutorial-part-ii.html.
In that tutorial, a base panel below the main one is used, so there is a little space to the left of the widget, but still the whole widget is aligned to the left of the screen.
Any idea how to fix this?
Thanks!
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    63.4 KB · Views: 309
Upvote 0

HappyDad

Member
Licensed User
Longtime User
Have you set the last parameter of CreateRemoteViews to True?
B4X:
ConfigureHomeWidget("L1", "rv", 60, "Hello Widget", True)

Thank you, Erel!

I didn't set the last parameter.
With it set, the widget does align to the center.

However, I am still having the sizing problem now.
I just tried out that I can set the panel size larger than 294 (which is 4 x 72 -2), and it is still a 4 cell widget horizontally.
I found that the actual size in pixels is twice the size I set in the designer.
So if I set the width of the panel to 350, the actual size of the widget will be 700 on my phone with 720 pixels horizontally.
I tried to follow this rule to set the height, but failed.
I see other 4 x 2 widget in my phone's height is larger than 400 pixels.
So I set my panel height to 200, after installing, the widget becomes a 4 x 3 widget.
I tried many values, and the maximum height I can set to have a 4 x 2 widget is 160.
After installing to phone, the widget is much shorter in height than other 4 x 2 widget.
 
Upvote 0

HappyDad

Member
Licensed User
Longtime User
The size will be scaled based on the dots per inch value.

Different devices use different cell sizes. The recommend approach is to use the minimum value.

Thanks!

Now I set the minHeigh and minWidth in <...>_info.xml to some values that the system treats it to be 4 x 2 widget.
Then set the xml file to be read only.
After that I change the panel in designer to bigger size.
Now the widget can occupy the whole 4 x 2 region!
 
Upvote 0
Top