zoukankan      html  css  js  c++  java
  • 控件:隐式抽屉 SlidingDrawer

    View Code
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.SlidingDrawer;
    import android.widget.SlidingDrawer.OnDrawerCloseListener;
    import android.widget.SlidingDrawer.OnDrawerOpenListener;
    import android.widget.SlidingDrawer.OnDrawerScrollListener;
    import android.widget.Toast;

    public class MySlidingDrawerDemo extends Activity {
    // 定义显示的数据
    private String data[] = {
    "大米稀饭", "www.cnblogs.com/androidsj",
    "讲师:Jason","IT技术博客", "www.cnblogs.com"};
    // 定义ListView组件
    private ListView listView;
    // 定义SlidingDrawer
    private 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();
    }
    }
    }

                        

  • 相关阅读:
    Max Sum of Max-K-sub-sequence(单调队列)
    Matrix Swapping II(求矩阵最大面积,dp)
    重温世界杯(贪心)
    Pie(求最小身高差,dp)
    Matrix(多线程dp)
    Python 实现自动导入缺失的库
    分布式系统session一致性解决方案
    数据结构 【链表】
    【数字图像处理】gamma变换
    【数字图像处理】顶帽变换和底帽变换
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379130.html
Copyright © 2011-2022 走看看