弄些简单的东西,留着给以后用
package com.temp;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
public class MoveIcon extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.move);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showButton();
}
});
}
PopupWindow popupWindow;
int mScreenX = 100, mScreenY = 200;
int mX, mY;
private void showButton() {
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.a);
popupWindow = new PopupWindow(imageView, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.showAtLocation((View) findViewById(R.id.parent), 0,
mScreenX, mScreenY);
imageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mX = (int) event.getX();
mY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
int delX = (int) (event.getX() - mX);
int delY = (int) (event.getY() - mY);
mScreenX += delX;
mScreenY += delY;
popupWindow.update(mScreenX, mScreenY, -1, -1);
break;
}
return true;
}
});
};
}