Android Bitmap don't refresh

2019-09-09 07:48发布

问题:

I need to create X number of bitmaps for different percentage values of a view (CircleDisplay). I always get the same BitMap. How can i load the different views to my listBitmap properly?

for(Goal g: goals) {

    ...

    Float percentageValue = (lastTrackDone.getDay_amount()/lastTrack.getDay_forecast()) * 100;

    //get goal circle image
    cd= (CircleDisplay) parentView.findViewById(R.id.circleDisplay);


    cd.setColor(Color.GREEN);
    cd.showValue(percentageValue, 100f, true);

    cd.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {

                    Bitmap bitmap = getBitmapFromView(cd);
                    listBitmap.add(bitmap);


                    loadCounter++;

                    if (numberGoals == loadCounter) {

                        cd.setVisibility(View.INVISIBLE);
                        cd.getViewTreeObserver()
                                .removeOnGlobalLayoutListener(this);
                        loadGoalsList();
                    }


                }
            });


    cd.destroyDrawingCache();
    cd.setDrawingCacheEnabled(false);

}

Best Regards