java - Canvas not update even I called invalidate()? -


I want to create a custom view that animates some lines, so I created a class that is view Enhances the class I OnDraw () & amp; Taken to the canvas, even some of the codes have been given that I have contacted so far.

  @Override Safe void onDraw (canvas canvas) {super.onDraw (canvas); P + = 10; Canvas Draaline (5, 5, P, 5, M.P.); Invalid (); }   

Note that P & The MPent is immediately translated on the container.

However, I have also called the invalid () method, it does not update the canvas, that does not animate the line.

So, how to solve it?

Are you sure this is not a drawing? What is the color of your paint object?

I created an empty 4.4 Android application, added this class:

  package ca.kieve.playground; Import android.content.Context; Import Android.graphics. Canvas; Import android.graphics.color; Import android.graphics.Paint; Import android.util.AttributeSet; Import android.view.View; Expansion of the public class AnimView [private int p = 0; Private Paint Mappant; Public Anime (Reference Reference) {Super (Reference); in this(); } Public Anniewue (Reference Reference, Attributed Atters) {Super (References, ethers); in this(); } Private Zero init () {mPaint = new paint (); MPaint.setColor (Color.RED); MPaint.setStrokeWidth (10); } @ Override Public Watch On Draw (Canvas Canvas) {Super. Don (canvas); P + = 1; Canvas Draaline (5, 5, P, 5, M.P.); Invalid (); }}   

and changed activity_main.xml to:

  & lt; Relative layout xmlns: android = "http://schemas.android.com/ apk / res / android" xmlns: tools = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "Match_parent" Android: paddingBottom = "@ dimen / activity_vertical_margin" Android: paddingLeft = "@ Dimen / activity_horizontal_margin" Android: paddingRight = "@ dimen / activity_horizontal_margin" Android: paddingTop = "@ dimen / activity_vertical_margin" tool: reference = "ca .kieve.playground.MainActivity "& gt; & Lt; Ca.kieve.playground.AnimView Android: layout_width = "match_parent" Android: layout_height = "match_parent" / & gt; & Lt; / RelativeLayout & gt;   

This is not a problem.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -