动画3份看法 [英] Animating 3 parts of a view
问题描述
我试图使该爬了号线到整数的应用程序认为,当presented用减法的问题,将呈现不断增长的矩形(或脂肪线)的动画。
我已经有东西设置,使我点击告诉我!和酒吧沿着显示被减数,减数和差数线条绘制的,但我希望能有负向积极的方向为正数的矩形爬行起来,负值为零。
在通过文档寻找似乎有几种不同的方式去了解这一点。我希望有人能提出一个方法那是相当简单的为这个新手来实现。下面是我已经找到了不同的方法:
这似乎很喜欢这个人的愿望,有柱状图,其中横杠弹出,但它没有一个答案。 Android的动画条形图(无效())
我已经详细阅读 http://developer.android.com/指南/主题/资源/绘-resource.html - 但我没有绘制,因为它是在查看被绘制。我想制作一些其余的在线视频<一个背景位图href=\"http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null?rq=1\">Android View.getDrawingCache返回null,只有空但我想三个矩形(对于被减数,减数和差)。
我已经想制作出一系列可绘制矩形,并显示他们一帧一帧显示的增长。
我已经看过<一个href=\"http://stackoverflow.com/questions/7291530/animation-at-a-specified-rate-using-canvas-ondraw\">Animation在用帆布/ OnDraw中,但不能辨别正是code来包装,如果的声明,如果事实上我的问题是重新绘制...
指定的速率我看了看使用路径 - 并把下面的code一起。如果方向问题,那么看来我应该能够慢下来,看的路径去那个方向,但它的瞬间。我发现我看到了一个例子的http:/ /www.curious-creature.org/2013/12/21/android-recipe-4-path-tracing/
如果(minuendLength大于0)// 0开始,到被减数长度 { path.addRect(interpX(0),yPosition(40),interpX(minuendLength),yPosition(43),Path.Direction.CW);
// interpX让我说,在数轴上什么号码就应该保持一致;
// yPosition是一路下跌屏幕个百分点。
canvas.drawPath(路径,minuendPaint);
//似乎一样的drawRect - 瞬间。
}
(在背景的数字线code如下,与进入不同大小的整数不同的选择:
IF((minuendLength&LT; 10安培;&安培; subtrahendLength小于10)及及(minuendLength&GT; -10安培;&安培; subtrahendLength&GT; -10))
{
this.setLineDimension(10); //默认
super.onDraw(画布);
canvas.drawLine(interpX(-this.getLineDimension()),yPosition(52),
interpX(this.getLineDimension()),yPosition(52),axisPaint);
INT步= this.getLineDimension()/ 5; //所以你不写* *所有的数字
//当他们进入数字,你让你自己的号码一致。
//描绘了小影线标记
为(中间体X = -this.getLineDimension(); X&下; = this.getLineDimension(); X + =步骤/ 2) canvas.drawLine(interpX(x)中,yPosition(52),interpX(x)中,yPosition(53),littleAxisPaint); //画上影线标记号码 textPaint.setTextAlign(Paint.Align.CENTER);
为(中间体X = -this.getLineDimension()+步骤; X&下; this.getLineDimension(); X + =工序)
{
canvas.drawText(Integer.toString(x)中,interpX(x)中,yPosition(56),textPaint);
}
}
最后我做这个用的Runnable。
animate.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
如果(((addend1大于0)及及(addend2℃,))) {
tempNum1 = addend1;
tempNum2 = addend2;
h.post(shrink1bigger);
}
否则如果(addend1&℃,放大器;&放大器; addend2大于0)
{
tempNum1 = addend1;
tempNum2 = addend2;
h.post(shrink2bigger);
}
}
});私人Runnable接口shrink2bigger =新的Runnable(){
@覆盖
公共无效的run(){ tempNum1 + = 1;
tempNum2- = 1;
shrinkDraw();
Log.i(WatchAnimActivity,tempNum1为+ tempNum1);
h.postDelayed(shrink2bigger,500);
checkTemp(shrink2bigger);
}};
私人无效shrinkDraw()
{ numLine.setFirstNum(tempNum1);
numLine.setNextNum(tempNum2);
numLine.invalidate();
}
公共无效checkTemp(Runnable的收缩)
{
Log.i(WatchAnimActivity,tempNum1在CHeckTemp为+ tempNum1);
如果(tempNum1 == 0 || tempNum2 == 0)
h.removeCallbacks(收缩);}
I am trying to make an app view that, when presented with a subtraction problem, will show an animation of a growing rectangle (or fat line) that crawls up the number line to that integer.
I already have things set up so that I click "show me!" and bars are drawn along the number line showing the minuend, the subtrahend and the difference, but I'd like to be able to have a positive number's rectangle crawl up in a positive direction, negative from zero in the negative direction.
In looking through the documentation there seem to be several different ways to go about this. I am hoping somebody can suggest a way that's reasonably simple for this novice to implement. Here are the different approaches I've found:
This seems very much like this person's desire to have a bar graph where the bars "pop up," but it doesn't have an answer. Android Animated Bar Chart (invalidate())
I've perused http://developer.android.com/guide/topics/resources/drawable-resource.html -- but I don't have a "drawable" because it's being drawn in the View. I'm thinking of making the rest of the number line a background bitmap per Android View.getDrawingCache returns null, only null but I want three rectangles (for the minuend, subtrahend and difference).
I have thought of making a series of rectangle drawables and showing them frame-by-frame to show the growth.
I have looked at Animation at a specified rate using canvas / Ondraw but cannot discern just what code to wrap in that "if" statement, if in fact my problem is re-drawing...
I looked at using Paths -- and put the following code together. If direction matters, then it seems I should be able to slow things down and watch the path going in that direction, but it's instantaneous. I found I saw an example at http://www.curious-creature.org/2013/12/21/android-recipe-4-path-tracing/
if (minuendLength > 0) // start at 0 and go to the minuend length
{
path.addRect(interpX(0), yPosition(40), interpX(minuendLength), yPosition(43) , Path.Direction.CW);
// interpX lets me say what number on the number line it should align with;
//yPosition is percent of the way down the screen.
canvas.drawPath(path,minuendPaint);
// Seems same as drawRect -- instantaneous.
}
(The number line in the 'background' code is as follows, with different options for different sized integers entered:
if ( (minuendLength <10 && subtrahendLength <10 ) && (minuendLength >-10 && subtrahendLength >-10 ) )
{
this.setLineDimension(10); // default
super.onDraw(canvas);
canvas.drawLine(interpX(-this.getLineDimension()), yPosition(52 ),
interpX(this.getLineDimension()), yPosition(52), axisPaint);
int step = this.getLineDimension()/5; // so you're not writing *all* the numbers
// when they enter numbers and you make your own number line.
// paints the little hatch marks
for (int x = -this.getLineDimension(); x <= this.getLineDimension(); x+=step/2)
canvas.drawLine(interpX(x), yPosition(52), interpX(x), yPosition(53) , littleAxisPaint);
// draw the numbers on the hatch marks
textPaint.setTextAlign(Paint.Align.CENTER);
for (int x = -this.getLineDimension() + step; x < this.getLineDimension(); x += step)
{
canvas.drawText(Integer.toString(x), interpX(x), yPosition(56), textPaint);
}
}
I ended up doing this using Runnables.
animate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ( ((addend1 > 0) && (addend2 < 0)) )
{
tempNum1 =addend1 ;
tempNum2 = addend2;
h.post(shrink1bigger);
}
else if (addend1 < 0 && addend2 > 0)
{
tempNum1 =addend1 ;
tempNum2 = addend2;
h.post(shrink2bigger);
}
}
});
private Runnable shrink2bigger = new Runnable(){
@Override
public void run() {
tempNum1+=1;
tempNum2-=1;
shrinkDraw();
Log.i("WatchAnimActivity", "tempNum1 is " + tempNum1);
h.postDelayed(shrink2bigger, 500);
checkTemp(shrink2bigger);
}};
private void shrinkDraw()
{
numLine.setFirstNum(tempNum1);
numLine.setNextNum(tempNum2);
numLine.invalidate();
}
public void checkTemp(Runnable shrink)
{
Log.i("WatchAnimActivity", "tempNum1 in CHeckTemp is " + tempNum1);
if (tempNum1 ==0 || tempNum2==0)
h.removeCallbacks(shrink);
}
这篇关于动画3份看法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!