Source code Activity [TestActivity.java]
package com.linedraw; //package name
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class TestActivity extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.DKGRAY);
setContentView(drawView);
}
}
Source code Activity [DrawView.java]
package com.linedraw; //package name
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, 20, 20, paint);
canvas.drawLine(20, 0, 0, 20, paint);
}
}
Output:
can you show the xml part?
ReplyDeleteNice, drew an x, nice and simple thanks
ReplyDeletewould put the project for download? or i it its not mind mail it to me : ka.esmaily@yahoo.com
ReplyDeleteyes but show us how you can draw this line inside a layout, between two other views, genius.
ReplyDelete