工程中需要这样的效果,左边和右边的Panel可以打开关闭:
我把左边和右边的Panel封装成2个类了。这里要特别注意,抽屉是需要“handler” 的,我这里可以把任何View都
看成“handler” ,使用setBindView(View bindView)方法进行绑定“handler” 。这样做的好处是“把手”可以独立于抽
屉,可以任意控制把手的位置,而不需要把手跟着抽屉移动!
先看左边的Panel:
Java代 码
1. import android.content.Context;
2. import android.os.AsyncTask;
3. import android.view.View;
4. import android.widget.LinearLayout;
5.
6. public class LeftPanel extends LinearLayout{
7.
8. /**每次 自动展开/收缩 的范 围*/
9. private final static int SPEED=20;
10. private int MAX_WIDTH=0;
11. private Context mContext;
12.
13. public LeftPanel(Context context,int width,int height) {
14. super(context);
15. this.mContext=context;
16. //设置 Panel本身 的属性
17. LayoutParams lp=new LayoutParams(width, height);
18. lp.leftMargin=-lp.width;
19. MAX_WIDTH=Math.abs(lp.leftMargin);
20. this.setLayoutParams(lp);
21. }
22. /**
23. *
24. * @param context
25. * @param width
26. * @param height
27. * @param bindView
28. * @param contentView
29. */
30. public LeftPanel(Context context,int width,int height,View bindView,View contentView)
{
31. this(context,width,height);
32. setBindView(bindView);
33. setContentView(contentView);
34. }
35. /**
36. * 把View放在 Panel中
37. * @param v
38. */
39. public void setContentView(View v){
40. this.addView(v);
41. }
42.
43. /**
44. * 绑定触发动画 的View
45. * @param bindView
46. */
47. public void setBindView(View bindView){
48. bindView.setOnClickListener(new OnClickListener(){
49.
50. @Override
51.