我想從float[]
中的點中劃出一條線。我知道這點得到了drawLines()
功能,因爲我在這裏記錄他們:爲什麼我的(自定義視圖)畫布上沒有繪製線條?
畫點:154.18182:784.8889:215.27272:677.3333: 215.27272:677.3333:337.45453:462.22217:337.45453:462.22217:276.36365:569.7778 :276.36365 569.7778 398.54544 354.66663 398.54544 354.66663 154.18182 784.8889 154.18182 784.8889 337.45453 462.22217 337.45453 462.22217 520.7273 139.55554 520.7273 139.55554 581.8182 32.0 581.8182 32.0 398.54544 354.66663 398.54544 :354.66663:154.18182:784.8889
* 注意:不支付注意重複點 - 第一行的終點是第二行的起點。 drawLines函數需要四個連續的點,因此重複點。
我width
和height
有效integers
:Width = 672 Height = 968
我onDraw
功能:
請注意,我已經嘗試過現在被註釋掉了幾件事情。我的背景是灰色的,所以Color.RED
行應該是可見的,當它被繪製時。
@Override
public void onDraw(Canvas canvas){
//setWillNotDraw(true);
Log.d(TAG, "DRAW DAMNIT!!!");
Log.d(TAG, "Width = " + (int) width + " Height = " + (int)height);
paint = new Paint();
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(4);
paint.setColor(Color.RED);
//paint.setAntiAlias(true);
//paint.setShadowLayer(4, 2, 2, 0x81000000);
Bitmap bitmap = Bitmap.createBitmap((int)width, (int)height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
String drawPointsGo = "";
float[] drawPoints = new float[points.size()];
for(int i=0; i<points.size(); i++){
Float f = points.get(i);
drawPoints[i] = (float) (f != null ? f : 0.0);
drawPointsGo = drawPointsGo + " : " + drawPoints[i];
}
Log.d(TAG, "Draw Points: " + drawPointsGo);
canvas.drawLines(drawPoints, paint);
}
我的XML:
<za.co.widge.test.linegraph.LineGraphView
android:id="@+id/linechart"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#444"
android:padding="16dp"
android:layout_weight="1"
/>
結果: 灰色塊出現在手機屏幕上,但沒有紅線繪製。
爲什麼沒有畫我的(自定義View
)canvas
?