onDraw() 方法未绘制所有位图

onDraw() method not drawing all of the bitmaps

我有一个应用程序可以根据人的生日绘制行星和星座。我在自定义 View 中使用 onDraw() 方法,该方法被添加到 XML 中的 FrameLayout。问题是,当我离开页面并调整日期时,activity 只绘制行星而不绘制新日期的黄道带标志。所有这些 "re" 绘图都发生在相同的 onDraw() 方法中,我可以看到 onDraw() 方法被调用,甚至是添加十二生肖位图的部分。鉴于正在调用它们,我无法判断出了什么问题,感觉它与位图有关。而且由于重新绘制了行星,所以我对问题可能是什么感到更加困惑。我已经包含了应该执行但未显示在屏幕上的代码。

    Log.i("ascendet planets", Integer.toString(ascendent));

    Bitmap capricornBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.capricorn);
    Bitmap aquariusBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.aquarius);
    Bitmap piscesBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pisces);
    Bitmap airesBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.aires);
    Bitmap taurusBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.taurus);
    Bitmap geminiBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.gemini);
    Bitmap cancerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cancer);
    Bitmap leoBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.leo);
    Bitmap virgoBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.virgo);
    Bitmap libraBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.libra);
    Bitmap scorpioBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.scorpio);
    Bitmap sagitariusBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sagittarius);


    ArrayList<Bitmap> bitmapArray = new ArrayList<>();
    bitmapArray.add(capricornBitmap);
    bitmapArray.add(aquariusBitmap);
    bitmapArray.add(piscesBitmap);
    bitmapArray.add(airesBitmap);
    bitmapArray.add(taurusBitmap);
    bitmapArray.add(geminiBitmap);
    bitmapArray.add(cancerBitmap);
    bitmapArray.add(leoBitmap);
    bitmapArray.add(virgoBitmap);
    bitmapArray.add(libraBitmap);
    bitmapArray.add(scorpioBitmap);
    bitmapArray.add(sagitariusBitmap);




    int bitmapWidth;
    int bitmapHeight;



    float x = 0;
    float y = 0;
    for (int i = ascendent; i < ascendent + 12; i++) {
        int multiplier = i - ascendent;
        bitmapWidth = bitmapArray.get(i%12).getWidth();
        bitmapHeight = bitmapArray.get(i%12).getHeight();

        x = (float) getPositionX(r_adjusted, marginOneSide, multiplier * 30 + 15, ascendent);
        y = (float) getPositionY(r_adjusted, height, multiplier * 30 +  15,          ascendent);

        x += bitmapWidth / 2;
        y -= bitmapHeight / 2;

        Log.i("bitmapWidth", Integer.toString(bitmapHeight));
        Log.i("bitmapHeight", Integer.toString(bitmapHeight));
        Log.i("i in planets", Integer.toString(i));

        canvas.drawBitmap(bitmapArray.get(i % 12), x, y, null);
    }

您是否尝试记录 "x" 和 "y"?经过所有计算后的值是否正确?