Problem:
I have an expandable listView. A group item can contain an orange triangle on the right side (as on the image). This triangle is derived from View and draws itself on a canvas, through the overridden onDraw method.
This works fine with two “exceptions” ;).
-
After the user scrolls through the list and after the scrollbar disappears, the space where the scrollbar was is not redrawn (cached?) correctly. I illustrated the problem on the following image:
The problem illustrated as image (Unfortunately I am not allowed to post a picture…) -
The same result (the third part on the right of the picture above) exists right after the activity started when there is more list content that can be displayed on one screen. e.g. if a scrollbar is necessary.
Of course I did some research around custom views and list view draw/view/cache problems. Unfortunately I did not find a matching answer.
Question:
Can you imagine what the source of the problem is?
Is there maybe a problem in the custom view? Do i have to pay attention on anything related to the problem, when using a custom view inside a list view?
I really appreciate your kind answers,
Diego
I found the problem now.
In the onDraw(Canvas canvas) overridden method, i used canvas.getClipBounds() to determine the rectangle of my view to paint the triangle on it.
This is maybe obviously wrong. Android wanted me to repaint the area where the scrollbar was, with a clip bound on the canvas set to this region.
I now use the View.getWidth() & getHeight Methods to determine the size of the area i can paint on.
An addition:
I think somehow it is strange, that it is not possible to determine the rectangle of the view i can paint on through the canvas. The canvas width and height are set to the values of the display resolution. Maybe someone has an interesting comment about…