package arabiannight.tistory.com.popupwindow;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Toast;
public class MainActivity extends Activity {
private PopupWindow mPopupWindow;
private Button btn_Popup;
int offset_x = 50;
int offset_y = 50;
int filstY = 0;
int filstX = 0;
int imgX, imgY;// 이미지 좌표
int lastX, lastY; // 최근 좌표
int thisX, thisY;// 현재 좌표
int deltaX, deltaY;// 변화량
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_Popup = (Button) findViewById(R.id.btn_click);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_click:
final View popupView = getLayoutInflater().inflate(
R.layout.popup_window, null);
mPopupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mPopupWindow.setAnimationStyle(-1); // 애니메이션 설정(-1:설정안함, 0:설정)
mPopupWindow.showAsDropDown(btn_Popup, offset_x, offset_y);
popupView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int eventX = (int) event.getX();
int eventY = (int) event.getY();
int X = (int) event.getX();
int Y = (int) event.getY();
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
thisX = eventX;
thisY = eventY;
// 좌표의 변화량을 구한다.
deltaX = thisX - lastX;
deltaY = thisY - lastY;
// 이미지 좌표에 반영한다.
imgX += deltaX;
imgY += deltaY;
// 현재좌표는 다음번에 과거의 좌표가 되야한다.
lastX = thisX;
lastY = thisY;
// TODO Auto-generated method stub
break;
case MotionEvent.ACTION_DOWN:
lastX = eventX;
lastY = eventY;
filstX = X;
filstY = Y;
break;
}
mPopupWindow.update(btn_Popup, imgX, imgY,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
return true;
}
});
break;
case R.id.btn_close:
if (mPopupWindow != null && mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
}
break;
case R.id.btn_bottom:
Toast.makeText(MainActivity.this, "Bottom UI 입니다.",
Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}
누른상태로 이동은되는데..부드럽게 안돼고..막 깜빡깜빡거리면서..불안전한데...왜그럴까요..??..