Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 4x1 size widget on Android homescreen?

I have difficulties developing 4x1 widget for Android.

This is the appprovider

<?xml version="1.0" encoding="utf-8"?> <appwidget-provider
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dp"
    android:minHeight="72dp"
    android:initialLayout="@layout/main" />

And here is the main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320dp"
    android:layout_height="100dp"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="horizontal"> 
//content goes here
</LinearLayout>

I could see the widget but the size is 4x2. I confuse why I cannot have 4x1 widget size?

Thanks

like image 667
stuckedoverflow Avatar asked Nov 12 '11 01:11

stuckedoverflow


People also ask

How do I stack widgets on Samsung?

To add a new widget, tap Add widget and tap one that you want to insert into the stack. If you want to change the order they show up in, simply long-tap one of the widgets in the list view and drag the up and down arrows to move the widget.


2 Answers

I don't think it's a newbie mistake.. I've had an appWidget that was 1x1 cell in size. I set it to 72dp x 72dp, and it was working fine.. But it seems like Google changed the widget dimension sizing formula from

(cells * 74) - 2

to

(cells * 70) - 30

So now the default size of my widget has to be 40dp x 40dp..

Source: http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#anatomy_determining_size

like image 99
Artiom Chilaru Avatar answered Sep 18 '22 03:09

Artiom Chilaru


In ICS it must be showing 4x2.

To correct this make a folder in 'res' name 'xml-v14':

Define your widget appwidget-provider with same xml name here. just change minHeight to 40dp. This will correct the error.

Hope this help you.

like image 22
E Player Plus Avatar answered Sep 19 '22 03:09

E Player Plus