0
我想在佈局中使用一些自定義視圖,如圖片所示。如何獲得獨立視圖的畫布
紅色矩形,它只是來看邊界。裏面可能有不同的東西。
對於我創建的自定義視圖:
公共類CustomView擴展視圖{
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(5, 5, 5, paint);
canvas.save();
}
}
中的onCreate,然後某處()方法,我的一些看法添加到佈局:
layout.addView(new CustomView(this));
layout.addView(new CustomView(this));
由於結果圓是繪製在佈局的左上方(黑色直腸在圖片上)。
我以爲onDraw()方法包含單獨視圖的Canvas。
如何在單獨視圖的範圍內繪製某些東西,但不是所有的佈局?
剛剛意識到你可能一直在談論如何使用畫布來做到這一點。但是,這應該能夠給你看你想要的。 – Andrew