One easy way to do this is to call the method directly against the data source during an event (i.e. button or link):
getComponent("viewPanelId").getDataModel().getDominoViewData().setExpandLevel(0); // 0 for collapse, 1 for expand
If the view data source is global to the page (or to a panel containing the event handler), not local to the view panel, you can skip all the chaining above and just refer directly to the var of the data source:
myView.setExpandLevel(0); // where <xp:dominoView var="myView" />