Reputation: 851
After I call the invalidate() method of my custom view (extends View) the onDraw() method is not called. This is caused by my app design but I not sure how to solve this problem.
I have two Layouts inside a FrameLayout (see below), which should work like layer in photo-editing software. In the code I add a different custom views to layout1 and layout2. After adding the second custom view to the second layout, the onDraw() method of this first custom view is not called after calling invalidate().
<FrameLayout
android:id="@+id/main_frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/main_layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/main_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</FrameLayout>
In both custom views I draw a bitmap over the hole screen size and draw some lines. The drawing is implemented in both custom views like:
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (w > 0 && h > 0) {
this.bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
}
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawBitmap(this.bitmap, 0, 0, new Paint());
drawSomeLines(canvas);
}
It all works fine if I only add one custom view to one layout. Has anybody an idea what is wrong with my structure/code?
Upvotes: 0
Views: 1132
Reputation: 851
I figured it out by myself, maybe the solution will help anybody.
The problem was that I added the custom views to different layouts. I removed the two LinearLayouts and added my custom views directly to the FrameLayout and it works fine.
Upvotes: 1