Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widget minHeight="72dp" gives 2 rows of height

I'm creating a basic widget that does nothing except display some static information (this is a tutorial demo exercise for me).

My widget provider XML looks like:

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

    <!-- NOTE 1: -->
    <!-- Widget sizing is done in terms of "blocks" on the screen. -->
    <!-- Each block is 74dp square. -->

    <!-- NOTE 2: -->
    <!-- OLD & WRONG FORMULA used to be: size = (n*74) - 2 -->

    <!-- NOTE 3: -->
    <!-- NEW FORMULA has been UPDATED: size = (n*70) - 30 -->
    <!-- Based on new formula, the size should be 40dp. -->

</appwidget-provider>

I want a widget that is 4x1. i.e. 1 row high.

Following the formula I've seen on many posts, height = (rows x 74) -2, I get a minHeight figure of 72dp which should provide me with a widget height of 1 row / block.

Installed on 4.1.1 gives me a widget that is 4x2.


Following from that, I thought maybe my layout was forcing the widget to be bigger than expected. So I removed everything from my layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</RelativeLayout>

Still 4x2 - 2 blocks high.

like image 223
Richard Le Mesurier Avatar asked Jan 16 '13 11:01

Richard Le Mesurier


1 Answers

The correct height to use (for 1 row / block) is:

android:minHeight="40dp"

Similarly, the correct width (for 4 columns / blocks) is:

android:minWidth="250dp"

I found the answer based on these 3 questions (which I should have checked first...)

  • Widget margins not applied on ICS phone with TouchWiz launcher?

  • Android 4x1 widget size

  • How to make 4x1 size widget on Android homescreen?


The reason is given by Artiom Chilaru in this answer

  • the formula has changed to size = (n*70) - 30

He gives a link to the App Widget Design Guidelines.

like image 179
Richard Le Mesurier Avatar answered Oct 23 '22 11:10

Richard Le Mesurier