Android中Widget的使用示例
2010-08-24 05:46:00 来源:WEB开发网Android中Widget的使用示例
之前已经写过通过重绘整个背景的方式,实现物体移动。今天要讲的是,
如何通过移动widget,view等控件,实现部分重绘。结合之前发Droiddraw工具,使用AbsoluteLayout,可以随意放置控件在任何位置。
package com.sky;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
import android.widget.Button;
@SuppressWarnings("deprecation")
public class AbosoluteMove extends Activity implements OnClickListener
{
/** Called when the activity is first created. */
public Button button1;
public Button button2;
public Button button3;
public Button button4;
Button tmp;//临时保存,选择的BUTTON
int x;
int y;
int flag;//用于标志选择哪个BUTTON
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1=(Button) findViewById(R.id.widget27);
button2=(Button) findViewById(R.id.widget28);
button3=(Button) findViewById(R.id.widget29);
button4=(Button) findViewById(R.id.widget30);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
button4.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.widget27:
flag=R.id.widget27;
setTitle("button1");
break;
case R.id.widget28:
更多精彩
赞助商链接