Never, ever, ever decode bitmaps from the onDraw() method. This is
going to cause big performance issues.

On Wed, Jun 22, 2011 at 11:41 PM, Zarah <[email protected]> wrote:
> Hi again! I tried creating a custom View that extends View so I can
> control how the image should appear and where it should appear.
>
> I override the onDraw() method like this:
> @Override
> protected void onDraw(Canvas canvas) {
>        super.onDraw(canvas);
>
>        Bitmap bitmapOrg =
> BitmapFactory.decodeResource(mContext.getResources(), mResourceID);
>
>        // ... set up image (scale, rotate, etc) ...
>        // (maybe this can be moved done before calling this method?)
>
>        canvas.drawBitmap(resizedBitmap, mXLocation, mYLocation, null);
> }
>
> It draws the image the size that I want it to be, at the coordinates I
> want to be. So far, so good. I tried adding two instances of this
> custom View and they appeared correctly. But I noticed that the bounds
> of each image spans the whole screen, so I cannot capture which of the
> two images was clicked.
>
> I tried changing the custom View to inherit from ImageView instead,
> and now the app can recognize which of the two images was clicked. BUT
> it doesn't draw where I want it to draw. All images are dumped on the
> upper left hand corner. :(
>
> If I can merge the two results, it would be perfect (I think!) for
> what I need.
>
> Any thoughts? :)
>
>
> Thank you so much!
> - Zarah
>
>
>
> On Jun 23, 11:45 am, Zsolt Vasvari <[email protected]> wrote:
>> If you want the simplicity of View objects, use the layout_margin as I
>> outlined above.
>>
>> The rotation should be doable via translation animations, if not, you
>> can certainly set up a Timer and change the View margins so they
>> appear is the new positions.  Now, if you need to rotate each
>> individual View so they appear as if they were on carousel, I am not
>> sure how to do that.  If they are just ImageButtons, you can probably
>> rotate and change their Drawables.
>>
>> On Jun 23, 10:23 am,Zarah<[email protected]> wrote:
>>
>>
>>
>>
>>
>>
>>
>> > Hi Nik and Zsolt! Thanks for your responses!
>>
>> > Yeah, I would need to have the conveniences of View objects (listeners
>> > and such). I would also need to be able to rotate the Canvas each time
>> > the user clicks and drags on an image and still be able to track which
>> > image was clicked.
>>
>> > -Zarah.
>>
>> > On Jun 23, 6:56 am, Zsolt Vasvari <[email protected]> wrote:
>>
>> > > But I think he wants the other niceties, such as the visible state
>> > > changes, etc, at least that way my impression.  Those things aren't
>> > > trivial to implement.
>>
>> > > Of course, if that's not a requirement, just use a Canvas object.
>>
>> > > On Jun 22, 10:15 pm, niko20 <[email protected]> wrote:
>>
>> > > > I would suggest using a Canvas and just drawing yourself. Then in the
>> > > > onTouch handler just do the match to find which circle was clicked.
>> > > > You could use RelativeLayout too if you wanted to use views.
>>
>> > > > -nik
>>
>> > > > On Jun 22, 5:56 am, Zsolt Vasvari <[email protected]> wrote:
>>
>> > > > > Yes, looks like it is.  Sorry, I didn't know that as I've never used
>> > > > > AbsoluteLayout.
>>
>> > > > > I guess you could use FrameLayout and then give each view an
>> > > > > appropriate layout_marginLeft and layout_marginTop.
>>
>> > > > > On Jun 22, 6:44 pm,Zarah<[email protected]> wrote:
>>
>> > > > > > Hi Zsolt!
>>
>> > > > > > But isn't that deprecated already?
>>
>> > > > > > -Zarah.
>>
>> > > > > > On Jun 22, 6:40 pm, Zsolt Vasvari <[email protected]> wrote:
>>
>> > > > > > > Use an AbsoluteLayout
>>
>> > > > > > > On Jun 22, 6:33 pm,Zarah<[email protected]> wrote:
>>
>> > > > > > > > Hi guys,
>>
>> > > > > > > > This is such a n00b question but I hope someone helps me. :)
>>
>> > > > > > > > I have always made apps that make use of traditional widgets 
>> > > > > > > > so when
>> > > > > > > > it comes to things like this I am totally at a loss. :(
>>
>> > > > > > > > Anyhooo, my aim is to display a set of images of beads into a 
>> > > > > > > > circle
>> > > > > > > > (sort of forming a bracelet), with each bead being clickable. 
>> > > > > > > > Some of
>> > > > > > > > the beads are not perfect spheres (some are oblong-ish), so I 
>> > > > > > > > would
>> > > > > > > > have to rotate the images by some degrees to either left or 
>> > > > > > > > right to
>> > > > > > > > make them look like they are stringed together.
>>
>> > > > > > > > I don't have an idea how to start doing this because I don't 
>> > > > > > > > know how
>> > > > > > > > I should tell the OS where to place the images. Should I use a 
>> > > > > > > > Canvas?
>> > > > > > > > Learn OpenGL?
>>
>> > > > > > > > If I use a Canvas, I would end up having a bitmap with all the 
>> > > > > > > > images,
>> > > > > > > > right? Can I still make the images clickable?
>>
>> > > > > > > > If I use OpenGL, is it an overkill? The main animation I would 
>> > > > > > > > have to
>> > > > > > > > do is simply have the circle rotate when the user clicks and 
>> > > > > > > > drags on
>> > > > > > > > a bead.
>>
>> > > > > > > > Thank you in advance!
>>
>> > > > > > > > -Zarah.- Hide quoted text -
>>
>> > > > > > - Show quoted text -- Hide quoted text -
>>
>> > > > - Show quoted text -- Hide quoted text -
>>
>> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Romain Guy
Android framework engineer
[email protected]

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

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

Reply via email to