Hendrik,

What are you actually trying to do? Do you need to replace buttons because your widget has several different versions, varying in size and the number of buttons?

If that's the case, consider using separate layouts, one for each widget size / number of buttons. You pretty much need this anyway, since initial widget size is specified in widget_info.xml, and there can only be one for each widget declared in the manifest.

Once you have a layout with the right number of buttons, you can change them individually with setImageViewResource and setOnClickPendingIntent. This has a side benefit, that only resource id and pending intent id are marshalled cross-process into the home application.

Also, I recommend using ImageViews for buttons. They respond to touch events, and you can add visual feedback by using a <selector> type drawable with an entry for <item android:state_pressed="true">.

Hope this helps.

-- Kostya


27.11.2010 2:27, Hendrik Greving пишет:
That's a good idea, I'll try that. By the way, if I want to replace one of the buttons from my widget provider per remoteviews, can I do this (for instance with removeAllViews and addView)? I've tried this and the widget than fails loading. Or do I need to set up a layout each for all possible combinations and then use this with updateAppWidget?

    ----- Original Message -----
    *From:* Kostya Vasilyev <mailto:kmans...@gmail.com>
    *To:* android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    *Sent:* Friday, November 26, 2010 3:07 PM
    *Subject:* Re: [android-developers] Re: custom view in widget

    Yes, portrait mode seems to be somewhat different. I don't have a
    tablet, but had to fix this for a Motorola Milestone (when the
    keyboard is pulled out, the home screen rotates).

    I did this by doing three things:

    - having separate layouts for portrait and landscape modes (you
    can use "res/layout_port", etc. in a widget);

    - specifying a larger width for the landscape layout (found
    empirically, so that my 2*1, 3*1, and 1*1 widgets line up at the
    edges when placed one below another);

    - using nine-patches for the backgrounds.

    One more trick would be to make use of layout_weight, although I
    haven't needed that.

    --
    Kostya Vasilyev -- http://kmansoft.wordpress.com

    27.11.2010 1:38 пользователь "Hendrik Greving"
    <fourhend...@gmail.com <mailto:fourhend...@gmail.com>> написал:
    > So basically the ideal image size for a standard 1-row widget
    would be 320x100 * 1.5? I did both the minimum APIlevel (7) and
    enabled scaling (true). The problem I have is that they don't
    scale in an (emulated-) tablet. The OS seems to scale the width
    more than the height. I played around with all setting I could
    imagine, scale type, minimum width, height,
    wrap_content/fill_parent, 9-patch png's. What would be the
    standard way to make this work? I saw widget's that apparently can
    do this.
    >
    > ----- Original Message -----
    > From: Kostya Vasilyev
    > To: android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    > Sent: Friday, November 26, 2010 2:08 PM
    > Subject: Re: [android-developers] Re: custom view in widget
    >
    >
    > When you read about standard widget sizes, that's in "dp" units:
    device independent pixels. On a high-res screen, your layouts are
    scaled by Android to a larger pixel size (a factor of 1.5 for hdpi).
    >
    > As for your issue with scaling - did you add support for scaling
    in the manifest? You can do it by either by setting minSdk to 4
    and above, or by including a <supports-screens> element.
    >
    > --
    > Kostya Vasilyev -- http://kmansoft.wordpress.com
    >
    > 27.11.2010 0:45 пользователь "Hendrik Greving"
    <fourhend...@gmail.com <mailto:fourhend...@gmail.com>> написал:
    > > I'm much further now, thanks. I have 5 button in a horizontal
    linear layout.
    > > Each button is currently 167x280. I read that a one row widget
    is normally
    > > 320x100. However, if I scale each button to 64x100, it looks
    bad, probably
    > > because I need the density?! On a high density screen like a
    Nexus one,the
    > > 167x280 look perfect. The other problem I have is, that it
    scales badly. I
    > > would like to at least make it look 'ok' when used on a
    tablet. However, it
    > > looks like that it scales only the width, and doesn't preserve
    the ratio.
    > > I've tried a lot with different scale types, I've also tried
    9-patch png
    > > images. If I do the latter, the button is scaled wrong in
    either case. Any
    > > idea? Thanks!!
    > >
    > > ----- Original Message -----
    > > From: "Mark Murphy" <mmur...@commonsware.com
    <mailto:mmur...@commonsware.com>>
    > > To: <android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>>
    > > Sent: Saturday, November 20, 2010 4:16 AM
    > > Subject: Re: [android-developers] Re: custom view in widget
    > >
    > >
    > >> On Fri, Nov 19, 2010 at 6:19 PM, Hendrik Greving
    <fourhend...@gmail.com <mailto:fourhend...@gmail.com>>
    > >> wrote:
    > >>> So basically the widget can only use stuff from the OS?
    > >>
    > >> Please read the documentation:
    > >>
    > >> http://developer.android.com/guide/topics/appwidgets/index.html
    > >>
    > >> particularly:
    > >>
    > >>
    
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
    > >>
    > >> where it lists the eligible classes for use through a
    RemoteViews.
    > >>
    > >>> Let's say you want
    > >>> to draw something nice into a widget, I saw several widgets
    doing that,
    > >>> like
    > >>> HTML content or so, or a picture from your mum (j/k), how
    would you do
    > >>> that?
    > >>
    > >> Since you neglected to point out any examples, and since it is
    > >> impossible to tell by looking at a set of pixels whether or
    not they
    > >> came from "HTML content or so", it is difficult to answer your
    > >> question.
    > >>
    > >> TextView supports SpannedString, such as that returned by
    > >> Html.fromHtml(). RemoteViews supports sending a SpannedString
    to an
    > >> app widget. Hence, you can use that subset of HTML supported by
    > >> fromHtml() in a TextView hosted by an app widget.
    > >>
    > >> Also, please bear in mind that home screens are not subject
    to app
    > >> widget limitations. So, just because you might see an HTC
    Sense or
    > >> MOTOBLUR home screen doing something fancy does not mean that
    an app
    > >> widget is capable of the same feats of derring-do.
    > >>
    > >> --
    > >> Mark Murphy (a Commons Guy)
    > >> http://commonsware.com | http://github.com/commonsguy
    > >> http://commonsware.com/blog | http://twitter.com/commonsguy
    > >>
    > >> _The Busy Coder's Guide to Android Development_ Version 3.2
    Available!
    > >>
    > >> --
    > >> You received this message because you are subscribed to the
    Google
    > >> Groups "Android Developers" group.
    > >> To post to this group, send email to
    android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    > >> To unsubscribe from this group, send email to
    > >> android-developers+unsubscr...@googlegroups.com
    <mailto:android-developers%2bunsubscr...@googlegroups.com>
    > >> For more options, visit this group at
    > >> http://groups.google.com/group/android-developers?hl=en
    > >
    > > --
    > > You received this message because you are subscribed to the Google
    > > Groups "Android Developers" group.
    > > To post to this group, send email to
    android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    > > To unsubscribe from this group, send email to
    > > android-developers+unsubscr...@googlegroups.com
    <mailto:android-developers%2bunsubscr...@googlegroups.com>
    > > For more options, visit this group at
    > > http://groups.google.com/group/android-developers?hl=en
    >
    >
    > --
    > You received this message because you are subscribed to the Google
    > Groups "Android Developers" group.
    > To post to this group, send email to
    android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    > To unsubscribe from this group, send email to
    > android-developers+unsubscr...@googlegroups.com
    <mailto:android-developers%2bunsubscr...@googlegroups.com>
    > For more options, visit this group at
    > http://groups.google.com/group/android-developers?hl=en
    >
    > --
    > You received this message because you are subscribed to the Google
    > Groups "Android Developers" group.
    > To post to this group, send email to
    android-developers@googlegroups.com
    <mailto:android-developers@googlegroups.com>
    > To unsubscribe from this group, send email to
    > android-developers+unsubscr...@googlegroups.com
    <mailto:android-developers%2bunsubscr...@googlegroups.com>
    > For more options, visit this group at
    > http://groups.google.com/group/android-developers?hl=en
-- You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to
    android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscr...@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to