Start here (and for this you need your input also for the part of the namespace "yourProjectNamespace"):
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/bTest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <sm.view.test.TheSurface android:id="@+id/vMain" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
In your TheSurface
Implement the features described above:
public TheSurface(Context C){ super(C); // Other setup code you want here } public TheSurface(Context C, AttributeSet attribs){ super(C, attribs); // Other setup code you want here } public TheSurface(Context C, AttributeSet attribs, int defStyle){ super(C, attribs, defStyle); // Other setup code you want here } protected void onDraw(Canvas canvas){ super.onDraw(canvas); Paint textPaint = new Paint(); textPaint.setColor(Color.WHITE); canvas.drawLine(0, 0, canvas.getWidth(), canvas.getHeight(), textPaint); // Other drawing functions here!!! }
This should make your drawing complete!
Also in my case you do not need to implement this as a SurfaceView, you can just implement it as a view, and it does not need to implement runnable !!!
source share