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. Notification doubt

is there a way to read a Notification in the program (via code!!!)?

--~--~---------~--~----~------------~-------~--~----~

2. Widget developer tired of "Doesn't launch" comments

All,

About one-fourth of comments for my widget on the market are "Doesn't
launch" with 1-star rating. Are you guys having the same problem? I've
already included the instructions at the top of app's description but
doesn't help. Here are the solutions I'm thinking about but don't know
how to implement them yet.

1. Having a default activity showing a help page. But this would
clutter the app tray with another useless app icon. Can I hide the app
icon from launcher after first launch?

2. Launch widget picker activity from the market open button. But this
doesn't tell users how to add widgets later on. Is it possible to set
AndroidManifest.xml to open widget picker as default activity?

Cheers
Jay

--~--~---------~--~----~------------~-------~--~----~

3. How to investigate current branches?

4. what are the main properties the video file must have to be played in android device?

5. INSTALL_PARSE_FAILED_NO_CERTIFICATES error

6. Force Close on startActivityForResult since 1.5 update on phones but not emulator

7. restart the phone to view the captured images in gallary