你的開發者或多或少正確,但你有選擇。默認情況下,Androidplot的BarRenderer僅在每個欄的頂部提供了一個可選標籤,這些標籤在iOS圖像中被「可用」,「新」,「已用」和「租用」標籤佔據。該標籤似乎未在您的Android屏幕截圖中使用,因此一種選擇是利用這些標籤來顯示您的總數。
就iOS實現與Androidplot完全匹配而言,缺失的部分是可以沿着每個條的側面水平和垂直添加其他標籤。您可以通過覆蓋它的onRender(...)方法來擴展BarRenderer。 Here's a link爲您的開發人員顯示了代碼中他想要修改onRender(...)的位置。
我建議這些修改,添加垂直標籤:
- 調用Canvas.save(Canvas.ALL_SAVE_FLAG)來存儲畫布的默認方向。
- 使用Canvas.translate(leftX,底部)到中心上的條形碼
- 旋轉畫布的左下點使用Canvas.rotate(90)90度,以使垂直文本繪製任何需要文本
- 繪製沿着劇情的一側; 0,0現在對應於條的左下角,因此在調用canvas.drawText(x,y)時從那裏開始。
- 調用Canvas.restore()來恢復畫布的原始方向。
執行上述操作後,添加橫向「%」標籤應該是不言而喻的,但如果遇到麻煩,隨時可以隨時提出更多問題。
更新: 這是上述的一個非常基本的實現。首先是drawVerticalText方法:
/**
*
* @param canvas
* @param paint paint used to draw the text
* @param text the text to be drawn
* @param x x-coord of where the text should be drawn
* @param y y-coord of where the text should be drawn
*/
protected void drawVerticalText(Canvas canvas, Paint paint, String text, float x, float y) {
// record the state of the canvas before the draw:
canvas.save(Canvas.ALL_SAVE_FLAG);
// center the canvas on our drawing coords:
canvas.translate(x, y);
// rotate into the desired "vertical" orientation:
canvas.rotate(-90);
// draw the text; note that we are drawing at 0, 0 and *not* x, y.
canvas.drawText(text, 0, 0, paint);
// restore the canvas state:
canvas.restore();
}
剩下的就是在必要時調用此方法。在你的情況下,它應該爲每個BarGroup完成一次,並且應該在y軸上保持一致的位置。我下面的代碼添加到堆疊的情況BarRenderer.onRender(...),馬上突破上方:
// needed some paint to draw with so I'll just create it here for now:
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(PixelUtils.spToPix(20));
drawVerticalText(
canvas,
paint,
"test",
barGroup.leftX,
basePositionY - PixelUtils.dpToPix(50)); // offset so the text doesnt intersect with the origin
這裏的結果的截圖...對不起,它是如此巨大:
就我個人而言,我不關心這些垂直標籤的固定y位置,並希望他們漂浮在酒吧的上部。要做到這一點我修改我的drawVerticalText的調用(...)看起來像這樣:
// needed some paint to draw with so I'll just create it here for now:
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(PixelUtils.spToPix(20));
// right-justify the text so it doesnt extend beyond the top of the bar
paint.setTextAlign(Paint.Align.RIGHT);
drawVerticalText(
canvas,
paint,
"test",
barGroup.leftX,
bottom);
將會產生這樣的結果:
尼克,謝謝。我會通過這個。 – user3042855