0

ここでアニメーションの完了後にテキストを描画するのに混乱しています。アニメーションの完了後に描画できるようにして、ここでDrawable temp = animationDrawable.getCurrent();メソッドに送信しようとsetDrawble(Drawable temp)
しました。最後のフレームにテキストを書き込んで、imagview に戻り、imagedrawable を設定しています。

他の方法も提案する

ここで私がしたことは私のコードを投稿しています

    ImageView imageview;
AnimationDrawable animationDrawable;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_keyframe_animation);

    imageview = (ImageView) findViewById(R.id.imageview);

    // Create the AnimationDrawable in which we will store all frames of the
    // animation
    animationDrawable = new AnimationDrawable();

    animationDrawable.addFrame(
            getResources().getDrawable(R.drawable.bingo_nw1), 0);

    // Run until we say stop
    animationDrawable.setOneShot(false);

    imageview.setImageDrawable(animationDrawable);

    imageview.setOnTouchListener(this);

}

protected void setBack() {
    // TODO Auto-generated method stub
    int num = 18;
    Random rand = new Random();
    int ran = rand.nextInt(num) + 9;

}

@Override
public boolean onTouch(View arg0, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {

        animationDrawable = new AnimationDrawable();

        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw2), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw3), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw4), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw5), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw6), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw7), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw8), 200);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.bingo_nw9), 200);

        imageview.setImageDrawable(animationDrawable);
        animationDrawable.start();

        Handler mHandler = new Handler();

        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

                Drawable temp = animationDrawable.getCurrent();

                imageview.setImageDrawable(setDrawble(temp));
            }

        }, 4000);
        return true;
    }
    return false;
}

@SuppressWarnings("deprecation")
public Drawable setDrawble(Drawable temp) {

    Bitmap bm = Bitmap.createBitmap(temp.getIntrinsicWidth(),
            temp.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bm);

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);
    paint.setTextSize(80);// Text Color
    paint.setStrokeWidth(12); // Text Size
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text
                                                                            // Overlapping
                                                                            // Pattern
    // some more settings...

    canvas.drawBitmap(bm, 0, 0, paint);
    canvas.drawText("Testing...", 10, 10, paint);

    temp.setBounds(100, 100, canvas.getWidth(), canvas.getHeight());
    temp.draw(canvas);

    return temp;
}
4

1 に答える 1