moqo
moqo view使用方法?
view使用方法?
1.写一个类继承View类,一般要重写ondraw方法。一般而言我们去自己绘制一个view,在另一个activity中setContentView(view)去引用它。
public class GameView extends View {
static int count 0 ;
static int y 0;
public GameView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
if (count100) {
count ;
}
else {
count 0 ;
}
Paint paint new Paint();
switch (count%4) {
case 0:
();
break;
case 1:
();
break;
case 2:
();
break;
case 3:
();
break;
}
canvas.drawRect((320-80)/2, y, (320-80)/2 80, y 40, paint);
super.onDraw(canvas);
}
}
2
写一个activity。
public class ViewTestActivity extends Activity {
/** Called when the activity is first created. */
public static GameView gameView;
public static Handler handler new Handler(){
@Override
public void handleMessage(Message msg) {
if (msg.what 11) {
}
super.handleMessage(msg);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView new GameView(this);
setContentView(gameView);
new Thread(new GameThread()).start();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case _DPAD_DOWN:
GameView.y 3;
break;
case _DPAD_UP:
GameView.y-3;
break;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return true;
}
}
class GameThread implements Runnable{
@Override
public void run() {
while (!().isInterrupted()) {
try {
(100);
} catch (InterruptedException e) {
();
().interrupt();
}
();//使用postnvalidate可以直接在线程中更新界面
}
}
}
detailsview控件怎么设置位置?
protected void Button1_Click(object sender, EventArgs e) { ; } 或者这样 protected void Button1_Click1(object sender, EventArgs e) { (); } 看看行不行