1 @Override
2 protected void onCreate(Bundle icicle) {
3 super.onCreate(icicle);
4
5 Context context = super.getApplicationContext();
6
7 /*Resources res = this.getResources();
8 // Problem may happen here!
9 // if set "R.layout.imagebutton" ,it hungs!!
10 XmlPullParser parser = res.getXml(R.layout.slidingdrawer);
11 AttributeSet attributes = Xml.asAttributeSet(parser);*/
12
13
14 // -------------------addImageButtons
15
16 // imagebutton
17 LinearLayout imageButtonLinearLayout = new LinearLayout(this);
18 imageButtonLinearLayout.setLayoutParams(new LayoutParams(
19 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
20 imageButtonLinearLayout.setOrientation(LinearLayout.VERTICAL);
21 // add imagebuttons
22 LayoutInflater inflater1 = (LayoutInflater) context
23 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
24 LinearLayout imagebuttonLinearLayout = (LinearLayout) inflater1
25 .inflate(R.layout.imagebutton, imageButtonLinearLayout, false);
26 imageButtonLinearLayout.addView(imagebuttonLinearLayout);
27
28 // --------------------add slidingdrawer over GLSurfaceView------
29
30 // place slidingdrawer in LinerLayout
31 LinearLayout slidingRightLinearLayout = new LinearLayout(this);
32 slidingRightLinearLayout.setLayoutParams(new LayoutParams(
33 LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
34 slidingRightLinearLayout.setOrientation(LinearLayout.VERTICAL);
35
36 // add sliding Drawer
37 LayoutInflater inflater2 = (LayoutInflater) context
38 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
39 SlidingDrawer slidingDrawer = (SlidingDrawer) inflater2.inflate(
40 R.layout.slidingdrawer, slidingRightLinearLayout, false);
41 slidingRightLinearLayout.addView(slidingDrawer);
42
43
44 super.setContentView(super.mView);
45 //setContentView(super.mView);
46
47 // ---------------------addContentView
48 addContentView(slidingRightLinearLayout, new LayoutParams(
49 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
50 addContentView(imageButtonLinearLayout, new LayoutParams(
51 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
52
53
54
55 // ----------------------- ImageButton Event
56 ImageButton imageButton1 = (ImageButton) this
57 .findViewById(R.id.imagebutton1);
58 ImageButton imageButton2 = (ImageButton) this
59 .findViewById(R.id.imagebutton2);
60 ImageButton imageButton3 = (ImageButton) this
61 .findViewById(R.id.imagebutton3);
62 ImageButton imageButton4 = (ImageButton) this
63 .findViewById(R.id.imagebutton4);
64
65 imageButton1.setOnTouchListener(new OnTouchListener() {
66
67 public boolean onTouch(View v, MotionEvent event) {
68 if (event.getAction() == MotionEvent.ACTION_DOWN) {
69 SetControlState(ZOOM_IN);
70 return true;
71 }
72 if (event.getAction() == MotionEvent.ACTION_UP) {
73 SetControlState(STOP);
74 return true;
75 }
76
77 return false;
78 }
79 });
80
81 imageButton2.setOnTouchListener(new OnTouchListener() {
82
83 public boolean onTouch(View v, MotionEvent event) {
84 if (event.getAction() == MotionEvent.ACTION_DOWN) {
85 SetControlState(ZOOM_OUT);
86 return true;
87 }
88 if (event.getAction() == MotionEvent.ACTION_UP) {
89 SetControlState(STOP);
90 return true;
91 }
92
93 return false;
94 }
95 });
96
97 imageButton3.setOnTouchListener(new OnTouchListener() {
98
99 public boolean onTouch(View v, MotionEvent event) {
100 if (event.getAction() == MotionEvent.ACTION_DOWN) {
101 SetControlState(ZOOM_IN);
102 return true;
103 }
104 if (event.getAction() == MotionEvent.ACTION_UP) {
105 SetControlState(STOP);
106 return true;
107 }
108
109 return false;
110 }
111 });
112
113 imageButton4.setOnTouchListener(new OnTouchListener() {
114
115 public boolean onTouch(View v, MotionEvent event) {
116 if (event.getAction() == MotionEvent.ACTION_DOWN) {
117 SetControlState(ZOOM_IN);
118 return true;
119 }
120 if (event.getAction() == MotionEvent.ACTION_UP) {
121 SetControlState(STOP);
122 return true;
123 }
124
125 return false;
126 }
127 });
128 }
转载于:https://www.cnblogs.com/maadiah/archive/2011/10/15/2212771.html