SlidingDrawer是一种抽屉型的组件,当用户选择打开此抽屉之后,会得到一些可以使用的“程序集”,这样当一个界面要摆放多个组件的时候,使用此组件就可以很好的解决布局空间紧张的问题
-
public class MySlidingDrawerDemo extends Activity {
-
private String data[] = { "北京魔乐科技", "", "讲师:李兴华",
-
"中国高校讲课联盟", ""}; // 定义显示的数据
-
private ListView listView; // 定义ListView组件
-
private SlidingDrawer slidingDrawer ; // 定义SlidingDrawer
-
private ImageView handle ; // 定义图片显示
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
super.setContentView(R.layout.main);
-
LinearLayout layout = (LinearLayout) super.findViewById(R.id.content) ;
-
this.listView = new ListView(this) ; // 实例化组件
-
listView.setAdapter(new ArrayAdapter<String>(this, // 将数据包装
-
android.R.layout.simple_expandable_list_item_1, // 每行显示一条数据
-
this.data)); // 设置组件内容
-
layout.addView(this.listView) ; // 增加组件
-
this.slidingDrawer = (SlidingDrawer) super.findViewById(R.id.slidingdrawer) ;
-
this.handle = (ImageView) super.findViewById(R.id.handle) ;// 取得组件
-
this.slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListenerImpl()) ;
-
this.slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListenerImpl()) ;
-
this.slidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListenerImpl());
-
}
-
private class OnDrawerOpenListenerImpl implements OnDrawerOpenListener {
-
@Override
-
public void onDrawerOpened() {
-
handle.setImageResource(R.drawable.ico_right) ; // 窗口打开监听
-
}
-
}
-
private class OnDrawerCloseListenerImpl implements OnDrawerCloseListener {
-
@Override
-
public void onDrawerClosed() {
-
handle.setImageResource(R.drawable.ico_left) ; // 窗口关闭监听
-
}
-
}
-
private class OnDrawerScrollListenerImpl implements OnDrawerScrollListener {
-
@Override
-
public void onScrollEnded() { // 拖动结束
-
Toast.makeText(MySlidingDrawerDemo.this, "窗口拖动结束。", Toast.LENGTH_SHORT).show();
-
}
-
@Override
-
public void onScrollStarted() { // 拖动开始
-
Toast.makeText(MySlidingDrawerDemo.this, "正在拖动窗口。", Toast.LENGTH_SHORT).show();
-
}
-
}
-
}
020716_隐式抽屉组件:SlidingDrawer.ppt
阅读(1250) | 评论(0) | 转发(0) |