Arbitrary positioning icon on a View

by Eric » Tue, 24 Nov 2009 10:32:54 GMT

Sponsored Links
 Hey all,

I'm trying to figure out how to mimic the "badge" functionality of an
iPhone particular, I've got a gridview that has several
icons, and based on the result of an AsyncTask, I'd like to position a
"new" badge hovering over one of the icons.  I've got the icon showing
up using Activity.addContentView but there don't seem to be any
ViewGroup.LayoutParams attributes to control an x/y position where the
new view should be displayed.  The options as I see them:

1) FrameLayout (also no support for offset that I can see)
2) RelativeLayout (can't figure out how to dynamically add a new
3) Create a large, mostly transparent png to handle the offset non-
4) Use AbsoluteLayout to specify pixel offsets.

Any other options I'm missing?  I'd really like to avoid using #3
(clunky) or #4 (deprecated)...any way to get #1 or #2 working?  Or is
there another option I'm missing?


Arbitrary positioning icon on a View

by Nithin » Tue, 24 Nov 2009 14:21:06 GMT

 Hi Eric,

Try offsetLeftAndRight() and offsetTopAndBottom() on the imageView, to
position it accordingly in the layout. But it is temporary only. Both
these offset will reset in the next layout pass.



Sponsored Links

Arbitrary positioning icon on a View

by » Tue, 24 Nov 2009 15:44:48 GMT

 Hi Eric,

Have you considered changing your adapter to provide the ImageView-s
nested in RelativeLayout-s?

This will let you do getParent().addView() on you icons.


Arbitrary positioning icon on a View

by Eric » Wed, 25 Nov 2009 07:58:52 GMT

 Thanks for the replies, guys.  I ended up using View.setPadding (the
temporary nature of the offset* methods was a bit too transitory for
my needs) to set a left/top padding on the ImageView, and it works
like a charm.


Arbitrary positioning icon on a View

by Dianne Hackborn » Wed, 25 Nov 2009 08:16:35 GMT


Given that you don't know when a layout pass will be needed, this is
probably a bad solution.

There are lots of options with the layout managers -- using relative layout
and specifying the appropriate parameters to position the badge view in the
corner, using a FrameLayout to layer two children on top of each other, etc.

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.


Other Threads

1. Seeding program phones. Anyone tried to activate their droid on a private account yet?

My phone just arrived today.  I haven't tried calling Verizon yet to
activate it.  But I found it confusing that the 2 page from Google
that came with the phone say "Please refer to the enclosed "Read Me
First" leaflet from Verizon Wireless for instructions to activate the
enclosed Droid."  There was no "Read Me First" leaflet from Verizon in
my package.


2. Kenapa 'Wajib' Pake Kartu Unlimited

Sekedar sharing, 

Semalam teringat sudah telanjur beli flash 50ribu sebelum ganti XL Unlimited di 
N1, cek quota flash begitu pasang simcard Simpati masih 117MB, kemudian lanjut 
liat YouTube mungkin liat sekitar 10-15 file, ga begitu ingat, ketiduran, 
begitu bangun langsung cek *889#...

Walah...tinggal 31MB...:))

Jadi pake Android wajib pake Simcard Unlimited...kalo ngak, silahkan menyuapi 
kartu anda dengan dollar hehehe

Semoga bermanfaat bagi yang masih pake kartu non Unlimited

Powered by Telkomsel BlackBerry

"Indonesian Android Community [id-android]" 

3. How to call another application from tabview

4. HELP! Cannot launch sub activity

5. Adding multiple images to AnimateDrawables sample code

6. how to use Remote Service?

7. Question on web service mobile client app for Android using ksoap2.