Resizable Widgets

Discussion in 'Android Questions' started by edgeryder1000, Feb 18, 2013.

  1. edgeryder1000

    edgeryder1000 Member Licensed 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?

  2. Erel

    Erel Administrator Staff Member Licensed User

    Seems like resizing only works on widgets based on ListView or Grid. Such widgets are currently not supported.
  3. edgeryder1000

    edgeryder1000 Member Licensed User

    Oh :( Thanks anyway. Maybe in the future we will be able to do this.
  4. corwin42

    corwin42 Expert Licensed 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.
  5. edgeryder1000

    edgeryder1000 Member Licensed User

    Ok thanks I'll look that up
  6. edgeryder1000

    edgeryder1000 Member Licensed User

    Yay it worked!
  7. Jost aus Soest

    Jost aus Soest Active Member Licensed User

    Please, do you have some working example?
  8. edgeryder1000

    edgeryder1000 Member Licensed User

    I'll post it tonight when I get home
  9. corwin42

    corwin42 Expert Licensed User

    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.
  10. edgeryder1000

    edgeryder1000 Member Licensed User
    (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.
  11. Jost aus Soest

    Jost aus Soest Active Member Licensed User

    Thanx a lot, corwin42 and edgeryder1000!
  12. erosmax

    erosmax Well-Known Member Licensed 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?

    This is the Code fo my xml layout :

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout xmlns: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" />

    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: May 30, 2014
  13. stanks

    stanks Active Member Licensed User

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

    Generating R file.                      Error
    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
  14. stanks

    stanks Active Member Licensed User

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

    corwin42 Expert Licensed User

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

    Yes, I have done this. If you know what you do, it works. :)
    stanks likes this.
  16. stanks

    stanks Active Member Licensed User

    thanks...i will try it
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice