Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:47:44+00:00 2026-06-06T06:47:44+00:00

Please bear with me if this isn’t clear, this is my first posting here.

  • 0

Please bear with me if this isn’t clear, this is my first posting here.

I’m drawing a couple of lines on a canvas and trying to translate the canvas to centre the lines on the screen. The trouble is, I have an actionbar (using actionbarsherlock) which I want to exclude from the translation i.e. I want the top of the view to be under the action bar.

As it is, the data is centred vertically on the whole screen height, but I want it to be centred vertically only on the visible part of the canvas under the action bar.

Any ideas of the best way to achieve this?

@Override
protected void onDraw(Canvas canvas) {
    Paint paint = mPaint;

    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.FILL);


    int centrew = canvas.getWidth()/2;
    int centreh = canvas.getHeight()/2;

    canvas.translate(centrew, centreh);
    canvas.drawLine(0, -5, 0, 5, mPaint);
    canvas.drawLine(5, 0, -5, 0, mPaint);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:47:47+00:00Added an answer on June 6, 2026 at 6:47 am

    The solution I used was as described here :

    http://developer.android.com/resources/samples/HoneycombGallery/src/com/example/android/hcgallery/TitlesFragment.html

    Basically my activity has the following layout listener defined:

    ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            mmv.setAbShift(MunroBag.this.actionBar.getHeight());
        }
    };  
    

    Then the view class has the following method defined:

        public void setAbShift(int shift)
        {
            abShift = shift;
            this.invalidate();
        }
    

    So onDraw gets called and the shift is applied to the view depending on the actionBar height.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question here so please bear with me - I apologise
this is my first time trying to use github so please bear with me..
This is my first post so please bear with me. I'm trying to execute
This is my first post on Stack, so please bear with me if I
This is my first time deploying a project so please bear with me. I
This is not a traditional scale-up or scale-out question. Please bear with me, here
Please bear with me on this one. I am first going to describe an
This is my first time using VBA in Outlook so please bear with me
Please bear with me, I am new to Uniscribe so I hope this isn't
This is my first post in any forum so please bear with me. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.