Why Ondraw Is Not Called After Invalidate()

Why onDraw is not called after invalidate()?

By default all ViewGroup sub-classes do not call their onDraw method, you should enable it by calling setWillNotDraw(false) link

Android Design: onDraw() not called after invalidate()

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.

Why is the onDraw Not Being Called in Custom View for Android?

You can remove View_path = new Drawpath_view(MainActivity.this); from your code,
as you already attached view in xml.

Invalidate does not call onDraw

Add an id

<labs.example.function.Draw
android:id="@id/draw"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</labs.example.function.Draw>

Replace

 final Draw draw = new Draw(this);

by

 final Draw draw = (Draw) findViewById(R.id.draw); // need to refer to the view in xml.

If you use final Draw draw = new Draw(this); you need to add that view to your view hierachy.

Custom View class' onDraw isn't called by Invalidate

invalidate() does not cause onDraw() to be called directly. It just tells the system that the view needs to be redrawn on the next drawing frame. Otherwise on the next drawing frame the system can use what was drawn previously since nothing has changed. In other words, your invalidate() call and the eventual onDraw() call are asynchronous.

Also, putting an infinite while loop in your constructor will cause the UI thread to never execute code beyond that point, so the system will never even complete a single layout pass and your view will never be drawn even once. Needless to say, do not do this.

Invalidate not calling onDraw()

instead of

dv = new DrawView(this); 

in your onCreate use:

dv = (DrawView)findViewById(R.id.drawView1);

your not using the drawview that is in the layout that you set to the content view



Related Topics



Leave a reply



Submit