I have custom View that should paint a bitmap. I've created a simple line(bmp 1x50 px) to check where will be drawn exactly. In my onDraw(Canvas c)
I'm using this line of code:
canvas.drawBitmap(bitmap, 0, 0, paint);
Where paint is simple Paint object, without any fancy settings. The problem is that this line shows at the middle of the view, not on top, as I thought it would be.
I'm setting View properties in layout xml:
<com.example.CustomView
android:id="@+id/costom_view"
android:layout_width="230px"
android:layout_height="188px"
android:layout_marginTop="10px"
custom:srcDraw="@drawable/menu_indicators_level_draw_up" />
This custom property is the ID of the bitmap I use to draw on canvas.
Why won't the View behave properly? And why does my canvas have a size if 800x450 (size of the screen i suppose) and not 230x188 like I defined in the layout?
And very important thing, I want to multiply the same bitmap on this view many times. At the end of work I want to draw this line from bottom to top of my View.
Copyright Notice:Content Author:「Prettygeek」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21302879/android-custom-view-dimensions-and-canvas-coordinates