我有一个应用程序根据人的生日画出行星和星座。我在自定义onDraw()
中使用View
方法,该方法已添加到FrameLayout
中的XML
。问题是,当我离开页面并调整日期时,活动仅绘制行星而不是新日期的星座。所有这些“重新”绘图都在相同的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);
}
答案 0 :(得分:1)
您是否尝试过记录&#34; x&#34;和&#34; y&#34;?在所有计算之后值是否正确?