开发者

How to provide alpha animation to each symbol instead of the whole view in android

I am creating a Typing Tutor application that has the options to type numbers, alphabets and characters. On selecting a particular option, the array gets loaded with either symbols. The following is my problem:

The activity that loads the array displays the symbols and display those on a random location of the activity. For this I have provided alpha animation for each symbol that appears for a period of time and vanishes off, the other symbol appearing after it. But I am not getting the desired result. The alpha animation is applied to the whole canvas view rather than each symbol. I want alpha animation for each symbol rather than the whole canvas view. Here is the code:

/*
 * Create a view that displays the animation.
 * This view will display the alpha animation 
 * The array is loaded and the elements are 
 * displayed in the random manner 
 */

class AnimationView extends View
{
    Animation animation;
    String str;
    Random randomLocationXY, randomValues;
    public AnimationView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub

    }

    private void createAnimation(Canvas canvas)
    开发者_JS百科{
        animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setRepeatCount(50);
        animation.setRepeatMode(Animation.REVERSE);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(10000l);
        startAnimation(animation);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);


        randomLocationXY = new Random();
        //randomValues = new Random();

        if(animation == null)
        {
            createAnimation(canvas);
        }

        Paint p = new Paint();
        p.setColor(Color.RED);
        p.setTextSize(40);
        p.setTypeface(Typeface.SANS_SERIF);

        for(int i=0; i< sel_array.length;i++)
        {
            int x = randomLocationXY.nextInt(canvas.getWidth());
            int y = randomLocationXY.nextInt(canvas.getHeight());
            str = sel_array[i];



            //draws the text at random location
            canvas.drawText(str, x, y, p);

        }

    }
}


hmm.. As far as I know in that case you have to create your animation (probably moving the postion of Text string as per your needs so that it looks like an animation. An another but processor intensive solution would be to provide the animation using different bitmaps (using canvas.drawBitMap).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜