SlidingDrawer控件,实现抽屉效果。
SlidingDrawer配置采用了水平展开或垂直展开两种(android:orientation)方式,在XML里必须指定其使用的android:handle与android:content,前者委托要展开的图片(Layout配置,即把手),后者为委托要展开的LayoutContent。
<SlidingDrawer android:id="@+id/sd" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/tv" android:content="@+id/sd_content" android:handle="@+id/sd_handle" android:orientation="horizontal" > <ImageView android:id="@id/sd_handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/open" /> <GridView android:id="@id/sd_content" android:layout_width="match_parent" android:layout_height="match_parent" android:numColumns="2" > </GridView> </SlidingDrawer>
在代码中,通过该控件的setOnDrawerOpenListener()与setOnDrawerCloseListener()方法监控抽屉的打开和关闭
sd.setOnDrawerOpenListener(new OnDrawerOpenListener() { @Override public void onDrawerOpened() { // TODO Auto-generated method stub sd_handle.setImageResource(R.drawable.close); tv.setText(getString(R.string.tv_close)); } }); sd.setOnDrawerCloseListener(new OnDrawerCloseListener() { @Override public void onDrawerClosed() { // TODO Auto-generated method stub sd_handle.setImageResource(R.drawable.open); tv.setText(getString(R.string.tv_open)); } });