In fact, you can inflate your layout from an XML file, and then get any view to draw it. SurfaceView is especially handy for drawing.
The following is an example:
main.xml:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <SurfaceView android:id="@+id/surface" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout>
TestActivity.java:
public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SurfaceView surface = (SurfaceView) findViewById(R.id.surface); surface.getHolder().addCallback(new Callback() { @Override public void surfaceCreated(SurfaceHolder holder) {
source share