Skip to content

1.2 Using DrawView

Oscar Gilberto Medina Cruz edited this page May 6, 2017 · 2 revisions

Add to your layout

For using DrawView you need to add to your layout file

<com.byox.drawview.views.DrawView
android:id="@+id/draw_view"android:layout_width="match_parent"android:layout_height="match_parent"/>

Initialize instance

From your java code, get the view from your layout for using later.

publicclassMainActivityextendsAppCompatActivity {
privateDrawViewmDrawView;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
...
mDrawView = (DrawView) findViewById(R.id.draw_view);
...
}
}

And you can set the OnDrawViewListener for controlling draw life cycle, in order:

  1. onStartDrawing when you tap down in screen.
  2. onEndDrawing when you tap up in screen.
  3. onClearDrawing when your screen has been cleared.
  4. onRequestText is executed when your DrawView has configured with text mode, and you tap up your screen for requesting for a text.
  5. onAllMovesPainted is triggered when all the user actions are completely drawn
mDrawView.setOnDrawViewListener(newDrawView.OnDrawViewListener() {
@OverridepublicvoidonStartDrawing() { // Your stuff here 
}
@OverridepublicvoidonEndDrawing() { // Your stuff here 
}
@OverridepublicvoidonClearDrawing() { // Your stuff here 
}
@OverridepublicvoidonRequestText() {
// Your stuff here 
}
@OverridepublicvoidonAllMovesPainted() {
// Your stuff here
}
}

Clone this wiki locally