0
是否可以在android佈局中使用canvas class
,如linear layout
和relative layout
。我正在嘗試在相對佈局中繪製一條線。使用帆布在android中的佈局
public class DrawDemoText extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.relativeMain);
}
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(Color.BLUE);
Path path = new Path();
path.lineTo(20, 0);
path.close();
path.offset(90, 120);
canvas.drawPath(path, paint);
}
}
}