Android Question Getting the widget image file the correct size

rleiman

Well-Known Member
Licensed User
Longtime User
Greetings Everyone,

I would like to know what the correct image file sizes and designer settings sizes I should use for all the different possible widget sizes such as 1x1, 1x2, etc. For example I wanted to create a 1x1 widget. The png file size is 128x128 pixels. The attachments show what the widget looks like in the designer and the actual screen real estate it occupies on my phone. I'm assuming either the image file size and / or the property size I have set in the designer is not correct for that size of image file. The widget seems to be taking up the space of a 2x2 widget.

Screenshot 2021-07-19 at 16.09.27.png
WhatsApp Image 2021-07-19 at 16.21.36.jpeg
 

rleiman

Well-Known Member
Licensed User
Longtime User
The size will be different on different devices.

The minimum size of a single block is 72x72.
Is there a way to eliminate the extra space shown in the attachment from post number 1? That's the attachment showing the outline box around the widget that's placed on the phone screen. It looks like it's occupying a 2x2 grid instead of 1x1. I already tried to make the widget smaller in the designer but it gets cut off not showing the entire image in the widget.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Are you setting the center property to true in ConfigureHomeWidget method? It will look a bit better.
Just made the change to ConfigureHomeWidget. It definitely helps. I also changed the size of the ImageView and Panel container to 70x70 and got the widget to a decent size. I still need to get that frame smaller so the user can move the widget around without it interfering with any other widgets the user has on their screen. The attachment shows the size of the frame Android thinks the widget actually is even though I have the width and height set to 70x70. Is that big frame in a property I can set either in code or in the designer? Judging by the size of the big frame, it looks like Android thinks the widget is a 3x3 widget, but it's supposed to be a 1x1 size.

WhatsApp Image 2021-07-22 at 15.51.07.jpeg
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
The size is determined by the size of the widget panel. You can get more options by creating the widgets XML layout yourself. Example: https://www.b4x.com/android/forum/threads/widget-layout-resizable-adaptive.115638/#content
With guidance from @Sagenut, that huge box frame around my app widget is now gone and the widget now fits in the Home Screen.

Here is the coding I used in my manifest:
Manifest Editor:
' Custom widget layout.
'----------------------
CreateResource(xml, quick_mute_full_widget_1x1_info.xml,
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:minWidth="60dp"
   android:minHeight="350dp"
   android:resizeMode="none"
   android:minResizeWidth="60dp"
   android:widgetCategory="home_screen"
   android:previewImage="@drawable/bluespeaker"
   android:updatePeriodMillis="1800000" />
)
CreateResource(layout, quick_mute_full_widget_1x1_layout.xml,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/quick_mute_full_widget_1x1_ImageViewSound"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</LinearLayout>
)

WhatsApp Image 2021-07-26 at 09.22.06.jpeg
 
Upvote 0
Top