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. Changing audio path to earpiece from speakerphone

Hi all. I'm trying to change the audio path to earpiece from
speakerphone, and I cannot get it to work on the G1: the audio always
goes through the speakerphone. Here's the code snippet:

/************************/
private AudioManager am;
am.setRouting(am.MODE_NORMAL, am.ROUTE_EARPIECE, am.ROUTE_ALL);
/************************/

I took logs for this issue and compared them to logs from the calling
app when I turn off the speakerphone there and they look similar:

(from calling app)
D/AudioFlinger(   35): setRouting 2 1 -1, tid 57, calling tid 58
E/AudioFlinger(   35): mA2dpDisableCount is already zero
I/AudioHardwareMSM72XX(   35): Routing audio to Handset
D/HTC Acoustic(   35): msm72xx_enable_audpp: 0x0000

(from my app)
D/AudioFlinger(   35): setRouting 0 1 -1, tid 54, calling tid 58
I/AudioHardwareMSM72XX(   35): Routing audio to Handset
D/HTC Acoustic(   35): msm72xx_enable_audpp: 0x0000

The main difference here is that I'm trying to change the audio path
for MODE_NORMAL, while the calling app is changing the audio path for
MODE_IN_CALL. Any suggestions or observations are helpful. Thanks.

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

2. webview + scrolling

Hi All,

I am trying to embedded a webview in a framelayout. my launch.xml is
as shown below.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</FrameLayout>


I have implemented the WebChromeClient and WidgetViewClient. I have
implemented the onTouchEvent and passing the touch events to the
WebView.

The problem i am facing is am not able to scroll inside the webview.
For example, the content is some 5 lines then am able to see only 3
lines and not able to scroll.

The touch events go to Webview, first action_down and then
action_move, am not able to get what wrong am doing??

I have this code also
mWebView.setHorizontalScrollBarEnabled(true);
mWebView.setVerticalScrollBarEnabled(true);

Is there anything else i have to set??

I have checked by replacing the FrameLayout with ScrollView by reading
some blogs but it didnt help..

Thanks in advance..

-- 

3. Where to put a broadcast receiver for a widget

4. Will this action bar navigation mode be the NAVIGATION MODE DROPDOWNLIST

5. Android 3.0 questions

6. [WTShare] CM7 Nightly for Nexus One

7. Downloading Application to phone