Kumail Hussain Kumail Hussain - 20 days ago 5
Android Question

Android : Widget 1*1 not adding up to screen

I have created an android widget

when i go to widget menu and select my created widget it shows , two widget 1*1 and 3*3

when i dragged the widget to my home screen it places only 3*3 widget and 1*1 Widget cannot be placed , can any one suggest me the right solution what i am missing.

My widget contain only one icon and i want the widget to be 1*1
here is my code :

Manifest.xml

<receiver android:name=".Main3Activity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/mywidget" />
</receiver>


xml/mywidget

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


activity_main3

<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"

tools:context=".MainActivity"
android:transitionGroup="true">

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Widget"
android:background="@drawable/widgeton"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />



Answer

According to Google the minimun width and height for a block in the home screen should be

70 × n − 30 for width and height now image is taking 1×1 screen size in home.

To work for 1*1 i have updated the layout to:

xml/mywidget

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