【发布时间】:2016-01-25 08:11:54
【问题描述】:
我有一个根据人的生日绘制行星和星座的应用程序。我在自定义View 中使用onDraw() 方法,该方法添加到XML 中的FrameLayout。问题是当我离开页面并调整日期时,活动只绘制行星而不是新日期的星座。所有这些“重新”绘图都发生在同一个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);
}
【问题讨论】:
标签: android view bitmap ondraw