返回列表 發帖

Android App - Sliding drawer

SlidingDrawer 隱藏式抽屜 is a container that when dragged or pressed shows/hides its contents.

As the SlidingDrawer displays one content at a time, it must be declared within FrameLayout

the SlidingDrawer has two key properties:
android:handle: specifies the id of the control that acts as the handle.
android:content: specifies the id of the view that acts as content of the SlidingDrawer, most times will be a container.

you can open/close the drawer from the code like this:
if(drawer.isOpened())    {     
      drawer.close();     
  btnToggle.setText("Open");    }   
else    {     
  drawer.open();     
  btnToggle.setText("Close");    }

you can open/close the drawer with animation using these methods instead

drawer.animateClose();
drawer.animateOpen();

or you can handle the open/close operations automatically using toggle method:

drawer.toggle();
drawer.animateToggle();

you can lock/unlock the SlidingDrawer to enable/disable dragging or clicking of the drawer using these methods:
drawer.lock();

drawer.unlock();

Responding to SlidingDrawer Events:

SlidingDrawer has three key callbacks:
  • when the drawer is open, handled by implementing OnDrawerOpenListener.
  • when the drawer is close, handled by implementing OnDrawerCloseListener.
  • when the drawer is close, handled by implementing OnDrawerScroll
    Listener.

drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {        

@Override   
public void onDrawerOpened() {     
// TODO Auto-generated method stub     
TextView txtStatus=(TextView)findViewById(R.id.txtStatus);     
txtStatus.setText("Opened");     
ImageView view=(ImageView)drawer.getHandle();     
view.setImageResource(R.drawable.tray_handle_selected);         
}   
});                                             

drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {        
@Override   
public void onDrawerClosed() {     
// TODO Auto-generated method stub     
TextView txtStatus=(TextView)findViewById(R.id.txtStatus);     
txtStatus.setText("Closed");     
ImageView view=(ImageView)drawer.getHandle();     
view.setImageResource(R.drawable.tray_handle_normal);   
}   
});                  

drawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {        
@Override   
public void onScrollStarted() {     
// TODO Auto-generated method stub     
TextView txtStatus=(TextView)findViewById(R.id.txtStatus);     
txtStatus.setText("Scroll start");         
}        

@Override   
public void onScrollEnded() {     
// TODO Auto-generated method stub     
TextView txtStatus=(TextView)findViewById(R.id.txtStatus);     
txtStatus.setText("Scroll end");   
}   
});

Notes:
Bill Tang     MSN:billtang@openplatform.com.hk
Openplatform Technology Co.,Ltd. 資訊坊科技有限公司  
無線工程施工、方案設計、無線產品、天饋材料、終端設備綜合供應商
Tel: 852-27491011  Fax: 852-81483532

返回列表