i designed an appwidget which should take up a width of 4 cells and a height of 1 cell.
Based on the docs this should be a 4x1 appwidget:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="40dp"
android:updatePeriodMillis="90000000"
android:previewImage="@drawable/widgetlayout_2"
android:initialLayout="@layout/main" >
</appwidget-provider>
Notice: @layout/main
has width and height match_parent
. It has nothing to do with the size of the appwidget
, that is why i don't post the XML-code
of main
.
Everythink works fine on phones, maybe because you can't rotate them when on the homescreen.
But on tablet(tested with Nexus 10 XHDPI 2560x1600 API16) the appWidget
is only measured with 3x1!
There is a similar question on stack with no answere. Maybe someone got an update.
The next issue is, that in landscape my design of the appwidget is as expected. But in Portrait, my appWidget
got shrinked on the homescreen, the layout is messed up? Does somebody know how to prevent this, my only Approach would be to define a layout-xlarge-port
Folder in my Project and put a customized layout for tablet in port mode in there?
Any help is appreciated!
In order to make a 4x1 cells widget, you need to specify your minWidth and minHeight using the following formula:
dpSize = (number of cells * 74) – 2
So mathematically, it should turned out to be:
android:minWidth="294dp"
android:minHeight="72dp"
These dimensions will set the default installation of your widget to 4x1 cells configuration. Installing your widget on tablets (which may have more than 4 horizontal cells) will also respect the same dimensions as shown in phones.
Regarding your second problem, you may define the following to restrict your widget's minimum re-sizeable width and height:
//for example this will set the minimum allowed re-size of 2x2 cells
android:minResizeWidth="146dp"
android:minResizeHeight="146dp"
android:resizeMode="horizontal|vertical"
I think its a good idea to not to define your widget's cell distribution more than 4x4 cells as this division easily fits for phones and tablets and let the user to re-size. But in case you have a desire for a larger cell division for tablets then I would suggest you to define multiple appwidget-provider
with custom cell configurations in folders respective to device screen densities. For example:
res
|-xml //for ordinary screens, like phones and phablets
|-xml-w820dp //for devices with minimum with of 820dp, like hi-res tablets and etc.