Android中Widget的使用示例
2010-08-24 05:46:00 来源:WEB开发网flag=R.id.widget28;
setTitle("button2");
break;
case R.id.widget29:
flag=R.id.widget29;
setTitle("button3");
break;
case R.id.widget30:
flag=R.id.widget30;
setTitle("button4");
break;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
// TODO Auto-generated method stub
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
// TODO Auto-generated method stub
x = (int) event.getX();
y = (int) event.getY();
tmp=(Button) findViewById(flag);//获取所选中的BUTTON
AbsoluteLayout.LayoutParams params1=new AbsoluteLayout.LayoutParams(50,50,x-25,y-50);
tmp.setLayoutParams(params1);//设置BUTTON的新位置
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
tmp.invalidate();
tmp.setText("选中down");
break;
case MotionEvent.ACTION_UP:
tmp.invalidate();
tmp.setText("选中UP");
break;
case MotionEvent.ACTION_MOVE:
tmp.invalidate();
tmp.setText("选中move");
break;
}
return super.onTouchEvent(event);
}
}
更多精彩
赞助商链接