在 android 中逐渐画线
Draw line progressively in android
我找到了一些画线的代码,现在我用魔杖逐渐画线,这样我就可以看到它被画出来了。
这是code
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, 20, 20, paint);
canvas.drawLine(20, 0, 0, 20, paint);
}
}
我该怎么做?
发送
你看到了吗?
查看源代码;)
http://www.curious-creature.com/2013/12/21/android-recipe-4-path-tracing/
您需要将绘图分成多个步骤。在 onDraw 调用中,您需要绘制一部分线,并更新一个变量以便绘制下一条线段。然后您将希望在动画循环中进行多次 onDraw() 调用。您需要注意从何处调用动画循环。阅读有关视图 class 的更多信息,特别是事件处理和线程。 http://developer.android.com/reference/android/view/View.html
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
float x1 = 0;
float x2 = 20;
float y1 = 0;
float y2 = 20;
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
if(doClear) {
//clear canvas to begin new animation
}
canvas.drawLine(x1, y1, x2, y2, paint);
}
public void animateLoop() {
while(x1 < 500) {
x1 += 20;
y1 += 20;
x2 += 20;
y2 += 20;
//tell android this view needs to be redrawn
invalidate();
}
//when done set doClear to true so
}
如果你真的想学习动画,你应该从这个例子开始:http://developer.android.com/guide/topics/graphics/drawable-animation.html。
我找到了一些画线的代码,现在我用魔杖逐渐画线,这样我就可以看到它被画出来了。
这是code
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, 20, 20, paint);
canvas.drawLine(20, 0, 0, 20, paint);
}
}
我该怎么做? 发送
你看到了吗? 查看源代码;) http://www.curious-creature.com/2013/12/21/android-recipe-4-path-tracing/
您需要将绘图分成多个步骤。在 onDraw 调用中,您需要绘制一部分线,并更新一个变量以便绘制下一条线段。然后您将希望在动画循环中进行多次 onDraw() 调用。您需要注意从何处调用动画循环。阅读有关视图 class 的更多信息,特别是事件处理和线程。 http://developer.android.com/reference/android/view/View.html
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
float x1 = 0;
float x2 = 20;
float y1 = 0;
float y2 = 20;
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
if(doClear) {
//clear canvas to begin new animation
}
canvas.drawLine(x1, y1, x2, y2, paint);
}
public void animateLoop() {
while(x1 < 500) {
x1 += 20;
y1 += 20;
x2 += 20;
y2 += 20;
//tell android this view needs to be redrawn
invalidate();
}
//when done set doClear to true so
}
如果你真的想学习动画,你应该从这个例子开始:http://developer.android.com/guide/topics/graphics/drawable-animation.html。