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);
}
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:
Then the view class has the following method defined:
So onDraw gets called and the shift is applied to the view depending on the actionBar height.