Android 动态增加控件
2010-08-21 06:34:00 来源:WEB开发网142. pb.setLayoutParams( LP_FW );
143. pb.setProgress( 45 ); // 设置第1进度为45
144. pb.setSecondaryProgress( 0 ); //这里我们不需要第2进度,所以为0
145. myLayout.addView( pb );
146.
147. Button bt = new Button(context);
148. bt.setLayoutParams( LP_WW );
149. bt.setText( "取消" );
150. myLayout.addView( bt );
151.
152. layout.addView( myLayout );
153. }
154.
155. @Override
156. public boolean onKeyDown(int keyCode, KeyEvent event)
157. {
158. Log.d("onKeyDown:", " keyCode=" + keyCode + " KeyEvent=" + event);
159. switch (keyCode)
160. {
161. case KeyEvent.KEYCODE_DPAD_UP:
162.
163. break;
164. case KeyEvent.KEYCODE_DPAD_DOWN:
165.
166. break;
167. case KeyEvent.KEYCODE_DPAD_LEFT:
168. //右左按键可以控制第一进度的增减
169. pb.setProgress( pb.getProgress()-5 );
170. break;
171. case KeyEvent.KEYCODE_DPAD_RIGHT:
172. pb.setProgress( pb.getProgress()+5 );
173. break;
174. case KeyEvent.KEYCODE_DPAD_CENTER:
175.
176. break;
177. case KeyEvent.KEYCODE_0:
178. break;
179. }
180. return super.onKeyDown(keyCode, event);
181. }
182. }
更多精彩
赞助商链接