Android Question How to make a widget which fits closely against other widgets

Martincg

Member
Licensed User
Longtime User
I need to provide a widget for an app I have written. The widget has to be positioned with other widgets from a different app (App1). The existing widgets for App1 all fit closely together in a neat grid and the tablet is used as an instrument panel
The widgets I have tried can't be placed next to the existing ones, and I can't get make a widget which is the same size as the existing ones. I've read that from SDK 14 widgets are forced to leave a space around themselves so I've tried using SDK 13 but it didn't make any difference that I can see.
I've installed App1 on my Nexus tablet, with Android 6.0.1, but I cannot get the widgets from App1 to but together in a grid like they do on my customer's tablets, one of which has Android 5.0.1 and the other has 7.1.2, so I guess it's partly because they have lower resolutions, but I don't know of course.

Widgets seem to be complicated to get right for different devices. Embarrassingly, I've already spent more time on the widget than I did writing the app.:confused: Can someone point me at something I should read to see what I should do?
 

Martincg

Member
Licensed User
Longtime User
It is possible that the multiple widgets you see are actually made of a single large widget.

No, the widgets for App1 are arranged as needed into a grid and each one is a widget which can show just one item of information. Each widget can be expanded from 1 x 1 to up to 4 down and up to 4 across. My app gets information that App1 can't, and then provides it to App1. My app supplies 3 pieces of information which requires 3 widgets. I have been asked to provide a single widget which shows all 3 pieces of information but I can't make a widget which will fit in with the others. I can get my widget close to another which is on the left, but not on the right, and I can't get my widget any closer to the bottom of the screen or any widget underneath it than two vertical grid pitches. When I try the example widget in Tutorial 1 that widget has similar problems.

Question
Could I use live wallpapers to draw an image in a part of the screen to make it look like the other widgets and change the wallpaper every 15 minutes, which is the rate at which data is updated? Then the part of the screen I draw in has the real widget arranged around it. The tablet is a single purpose device, it is only used as a display panel for reading of a control system. To set the correct region for the drawn image I could have the app acting as a web server, then the customer could adjust the size and position from some other device to get it right.
Or am I just completely mad?

I have noticed that if I create a widget which is 72 wide by 180 high and place it on the home screen then I can fit it at the bottom of the screen or I can put another widget next to it on any edge. But on the right and bottom edges there is a big gap which I want to get rid of. If I increase the widget size to 100 wide x 216 high and install it then the widget on the home screen becomes the new size and I can position other widget around it without the big gap.
If I delete the widget and place a new one on the screen I can no longer fit widgets to the right or underneath. So I think that the widget object has the 'graphics' information and the 'space it needs' information, but only the graphics gets updated when an updated widget is installed. Does this give anyone a clue about how I could make a widget which works as I want without having to install two versions in succession?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Martincg

Member
Licensed User
Longtime User
OK. Widgets aren't the correct way to display lots of data IMO.
I've persuaded my customer to abandon widgets and use a full screen graphical representation of the whole system. My app can get the data for all the sensors and update overlays on the graphic. Funny how a simple job which will take a few hours turns into a lifetimes work.
 
Upvote 0
Top