Displaying the Image in the screen center using Canvas

by Nandagopal T » Thu, 21 Apr 2011 03:17:53 GMT


Sponsored Links
 I am using the canvas to display an image in Android. I want an image
to occupy the center of the screen irrespective of the sizes of the
screen. So how could i achieve it.

This is the snippet that i tried with, Please let me know your ideas
too.

@Override
        protected void onDraw(Canvas canvas) {
        ..........
            ..........
             // This moves the image to right end of the view.
            sampleImage.draw(canvas,getWidth(),getHeight());
            // Tried with this code too, but not getting the image at
the center of the screen.
            sampleImage.draw(canvas,getWidth()/2 - imageWidth/
2 ,getHeight()/2 - imageHeight/2);

            ..........
            ..........


Thank you


-- 



Re: Displaying the Image in the screen center using Canvas

by Kromosome » Thu, 21 Apr 2011 09:58:53 GMT


 Check this out:

 http://developer.android.com/reference/android/widget/LinearLayout.html 

Look under the XML Attributes heading!




-- 


Sponsored Links


Re: Displaying the Image in the screen center using Canvas

by Tuan.B » Fri, 22 Apr 2011 03:39:25 GMT


 My guess is you want to draw it on the center of the screen, in your
code you refer to the canvas position, then the code you provided will
centered the sample image according to the canvas... so it depend on
how you declared you View referred by your canvas.





-- 



Other Threads

1. Query bluetooth devices. Is it possible?

Hi,

I know there isn't bluetooth API in 1.0 SDK, but I have a doubt.
I need to know the visible bluetooth devices. That is, I only need do
a scan of the bluetooth devices and save the diferent addresses. I
don't need connect to them.

I have read here

2. How to write code for centre button

Hi,

I am writing an application. I am using ExpandableListActivity, I
mean,  I  am showing some List elements,

for example I show some country names, when some one clicks (touches)
a particular country, the list automatically expands and shows the
available states in the country.

If I click on (touch) any state, it should show an alert with the
state name showing.

It works fine when I touches the screen. But I want the same thing
should be happen when I press the centre key of the emulator's keypad
(left, top, right, bottom, centre or fire keys).

I dont know how to write code for this requirement.

Can any one please help me?

Thanks,
Manoj.
--~--~---------~--~----~------------~-------~--~----~

3. Does recording and playback works simultaneously on android on omapzoom?

4. link error on code.google.com

5. Can I manage making a call or sending a text?

6. the problem with libopencoreplayer.so when compile Android source code

7. Audio Streaming Integration