Resizable Widgets

edgeryder1000

Member
Licensed User
Longtime User
I am working on a resizable analog clock widget. Everything works fine, except when the user resizes the widget the actual clock stays the same size. That
is, the widget takes up more space, but looks the same size.
How can I make the widget expand when it is resized?

Thanks
 

corwin42

Expert
Licensed User
Longtime User
I think Erel and you are talking about two different things.

Many custom launcher have the ability to resize any widget. Widgets created with B4A have a very static layout because they use AbsoluteLayout for grouping their views.

If you look in the Objects/res/layout folder of your B4A project you will see the xml layout for the widget. With some knowledge about Android XML Layouts you can modify this xml file and change the AbsoluteLayouts to RelativeLayout or LinearLayout to make it more "scaleable". Then make the layout file read only and you are done.

Be aware that this is some work and you need some experience with Android xml layout files but it IS possible.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Please, do you have some working example?

You can try this: WorldClock Widget

This example includes (nearly) everything that is currently possible with B4A and widgets. May be a bit complicated because it demonstrates many advanced features in one project.
 
Upvote 0

edgeryder1000

Member
Licensed User
Longtime User
https://docs.google.com/file/d/0B33a3v2QIrbBaTZyY1p5RWNENEk/edit?usp=sharing
(File is 0.8MB)

Simple example of a resizable widget which also works on 4.2 lockscreen.
(Needs latest sdk for lockscreen)

To disable lockscreen ability, remove the bit in widget_info.xml that says something like "android:category=keyguard"

For resizing you need to have "android:resizeMode=horizontal|vertical" in your manifest and then edit the layout.xml file and change some "absoluteLayout"s to "relativeLayout"s. Just look at layout.xml in the example.
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
Hi, I've two bitmap (ImageView1 and ImageView2) into my Panel...
While for the first image, Iit's done with it becomes large as the panel... but for the second, I could use a height of less than 20%. How can I make usingwith "match_parent" in size, for decrease?
Thanks

This is the Code fo my xml layout :

B4X:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">
  <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:eek:rientation="horizontal" android:gravity="center" android:layout_x="0dp" android:layout_y="0dp">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:eek:rientation="vertical" android:gravity="center" android:layout_gravity="center_vertical">
      <RelativeLayout android:id="@+id/stay_on_panel1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_x="0dp" android:layout_y="0dp">
        <ImageView android:scaleType="fitCenter" android:id="@+id/stay_on_imageview1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_x="0dp" android:layout_y="0dp" android:visibility="visible" />
        <ImageView android:scaleType="fitCenter" android:id="@+id/stay_on_imageview2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_x="0dp" android:layout_y="0dp" android:visibility="visible" />
      </RelativeLayout>
    </LinearLayout>
  </RelativeLayout>
</AbsoluteLayout>


PS: In Bold, at last lImageView onto code, I've sign the Height when I want resize to 20% low :(

<ImageView android:scaleType="fitCenter" android:id="@+id/stay_on_imageview2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_x="0dp" android:layout_y="0dp" android:visibility="visible" />
 
Last edited:
Upvote 0

stanks

Active Member
Licensed User
Longtime User
well for me it doesn't work....if i set read only my widget layout file i am getting err:

B4X:
Generating R file.                      Error
res\layout\eventim_layout.xml:4: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/pozadina7').
res\layout\eventim_layout.xml:5: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/eventim_logo').
res\layout\eventim_layout.xml:6: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/osvjezi').
res\layout\eventim_layout.xml:8: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/plava_gore').
res\layout\eventim_layout.xml:9: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/plava_dole').
res\layout\eventim_layout.xml:10: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/opcije').

And widget_info from res/xml dir is changed too by B4A so everytime i set android:resizeMode="horizontal|vertical" it is rewritten by B4A
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
well for me it doesn't work....if i set read only my widget layout file i am getting err:

B4X:
Generating R file.                      Error
res\layout\eventim_layout.xml:4: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/pozadina7').
res\layout\eventim_layout.xml:5: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/eventim_logo').
res\layout\eventim_layout.xml:6: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/osvjezi').
res\layout\eventim_layout.xml:8: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/plava_gore').
res\layout\eventim_layout.xml:9: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/plava_dole').
res\layout\eventim_layout.xml:10: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/opcije').

And widget_info from res/xml dir is changed too by B4A so everytime i set android:resizeMode="horizontal|vertical" it is rewritten by B4A

Are all these drawables images in your layout? Copy them to the drawable folder and make them read only, too.

btw did anyone tried to make widget in eclipse and then copy it to B4A?

Yes, I have done this. If you know what you do, it works. :)
 
Upvote 0
Top