I have Android widget that contains two buttons. But i have no idea how big my widget should be for different DPI. According to this, it's easy to calculate, but my widget isn't square, it's rectangle, how to calculate it's size?
My widget-provider.xml looks like this:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="160dip"
android:minHeight="72dip"
android:updatePeriodMillis="0"
android:initialLayout="@layout/main"
/>
For resizable widgets, press firmly on the widget on your home screen. 2. A white box with circular adjustment markers will appear around the widget. Slide them in or out to make the widget smaller or larger, respectively.
There are given a lot of android widgets with simplified examples such as Button, EditText, AutoCompleteTextView, ToggleButton, DatePicker, TimePicker, ProgressBar etc.
To get the size/position of a widget on screen, you can use GlobalKey to get its BuildContext to then find the RenderBox of that specific widget, which will contain its global position and rendered size.
I would take a look at the widget design guidelines, specifically the section about widget sizes. It specifies the size in px, but you should be able to convert them to dp for a given density.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With