It's a bit of a frustration that as of Android 4.0, app widgets are automatically given margins between the widget frame and the app:
The space on a small phone's screen is at a premium, and the margin can represent quite a large loss, particularly when the widget is small too. Despite hours of looking, I can't see a way to override or control the widget's margins.
However, I have been playing recently with the Nova launcher, and note that it's possible to control widget margins using that launcher. What is more, although there's a global widget margin setting (something like None, Small, Medium, Large), this setting can be activated per widget.
And it's lovely to get widgets that extend from edge to edge. See, for example, the following screenshot from my meteogram app:
So, the question is... how does the Nova launcher control widget margins, and can the same method be used at the widget level, or does the control necessarily come from launcher level so that there is no hope for ever controlling widget margins unless you're a launcher developer?
Your assumptions are correct.
Widget margin control lies with launcher so there is not much you can do about it unless you build a launcher.
Related
I would like to integrate widgets that correspond to App actions voice commands into the Google Assistant. I've been following the documentation here and everything seems to work fine. I have one issue i cant seem to find a solution for, and that is a way to control the widget height accurately based on its content.
The documentation everywhere treats these Google Assistant widgets as ones that need to also be surfaced to the home screen, and therefore are also constrained by the home screen cells limitations (see here). But i just want to surface them to Google (aka Assistant), which is not bound to the same limitations.
From what i've seen with existing Assistant widgets, they are pretty flexible and adjusting pretty nicely to whatever content they are showing.
Examples: check the widgets shown by saying "Whats the weather?" (height: 440px), "Get info about Schiphol airport" (height: 264px), "Navigation direction to Schiphol airport" (height: 362px), "Whats the time?" (height: 156px).
Is there a way to adjust these widgets' height on the fly that im missing?
Is there any way I can achieve the desired behaviour on rotation of the device, as illustrated in the following sketch (the wavy thing is a widget). Most likely this is something that would be controlled by the launcher, rather than controlled programmatically from any one app -- if so, is there any launcher that allows this?
Basically the reason I'm asking is because I want the widget to behave as illustrated (the widget is what I'm coding), even when the user's device is set to rotate the home screen on device rotation. Basically the only way I can see this working is if the grid layout is fixed relative to the physical screen, with the app icons just rotating within their box, and the widgets either updating their content for the new layout, or just keeping the previous content (so that the content rotates with the screen).
For updating of widget content, is there any way of detecting screen home screen rotation programmatically (different to screen rotation, since the home screen may not rotate)? This is relevant to me even for the "what I get" scenario, because the aspect ratio of the widget seems to change when the home screen is rotated, and I need to detect this and update the widget content to fit better.
dfdd
Use:
1. layout-sw480dp
2. layout-sw600dp
3. layout-sw720dp
You are unlikely to find a solution for this as the home screen (launcher) varies wildly in implementation. Many launchers don't support landscape orientation, and expecting the launcher to accommodate a widget which can expand in two different directions is simply asking too much of them.
For the launchers which do support landscape orientation, the widget should be repositioned for free without effort on your part. You may wish to detect which orientation the widget is in (such as via getResources().getConfiguration().orientation) when your provider is choosing a layout, setting up views etc, but that's about it.
I have built an appwidget with an square layout, and so it doesn't fit exactly in the standard widget sizes as recommended in http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#sizes.
I chose a 3x2 size (android:minWidth="220dip" android:minHeight="146dip") as it is the smalllest that covers the widget's layout.
In http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#design Google recommends:
"All widgets must fit within the bounding box of one of the six supported widget sizes, or better yet, within a pair of portrait and landscape orientation sizes, so your widget looks good when the user switches screen orientations"
My widget looks good in portrait mode. When switched to landscape mode (in the emulator) the layout is clipped. I tried inverting the minWidth and minHeight values in the provider's XML and then it looked perfect in landscape mode but clipped in portrait mode. Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.
I know I can define different layouts in res/layout and res/layout-land, but in this case the layouts are not different at all, in both modes I want the widget to look square.
What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.
Ideas?
What I would need is something like 'xml' and 'xml-land', AFAIK this is not supported in Android.
It is supported. All resource set qualifiers (e.g., -land) are supported for all resource types.
Whether it will help you is another matter entirely, as I am not aware that you can change actual app widget size on the fly this way.
Setting the size to 3x3 solves the problem, but then the widgets takes a lot of unnecessary space.
You are the one who is trying to force a particular pixel size (or, at least, aspect ratio). This will be fragile, as you are discovering. Furthermore, app widget cells are not guaranteed to be the same size on all devices and home screen implementations.
Hence, you are either going to need to choose an app widget size that gives you tons of extra space (your 3x3 scenario), or design a fluid app widget layout that adapts to the actual size that you are given (and therefore will not be square). Personally, I recommend the latter.
On Android the user can place a widget on the desktop and then to move it by long touch and moving the finger while still holding.
Is it possible to programmatically get the position on the screen where the widget was moved by long touch?
I need my desktop widget to know if it's near the edge of the screen of the device. Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen.
I would expect that this position is not given in pixels, but as pair of 0-based indexes. E.g. if the device can display 4x7 cells on the desktop, the widget in the bottom-right corner should have coords (3, 6). Also it should be somehow possible to ask the device how many cells fit into the screen.
Or am I misunderstanding something?
On Android 2.1 and later, with some select home screens, you can find out where an app widget resides when it is clicked via getSourceBounds() -- this value is attached to any Intent you spawn via a PendingIntent via setOnClickPendingIntent().
However:
this only works on Android 2.1 and newer
not all home screens might do this, as this is part of the Launcher code IIRC
the coordinates are in pixels IIRC
there is no way to interrogate the home screen to find out this information any other way, since there is no API to interact with the home screen
Hence, I think your stated goal ("Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen") is impossible, I think.
I have a use-case for a vertical 1x4 home screen widget on android. The supported size is 4x1 ie horizontal. Does anyone know if the vertical version can be implemented?
I realize changing screen orientation would scrunch the widget together, which I'm fine with. Even better would be if there was an equivalent to "overflow hidden" in css.
Has anyone come across a way to do this?
this seems like the wrong answer. at least as far as i can tell with android-7 platform and above, you can set the size however you want up to the full screen. of course, that's not the recommended sizes, but there's nothing technically restricting you from implementing the widget you're talking about. an issue to watch out for is that while you can supply different layouts for portrait and landscape, onUpdate won't be called on a screen rotation.
No, you can't do this. Sorry.