Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate appropriate android widget size?

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"
    />
like image 420
guest86 Avatar asked Sep 07 '11 17:09

guest86


People also ask

Can you change widget size on android?

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.

Is an example of standard widget in Android?

There are given a lot of android widgets with simplified examples such as Button, EditText, AutoCompleteTextView, ToggleButton, DatePicker, TimePicker, ProgressBar etc.

Which function returns the height of a widget in Android?

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.


1 Answers

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.

like image 98
Erich Douglass Avatar answered Nov 14 '22 21:11

Erich Douglass