我想制作一个拖放按钮,将其拖到所需位置并使其保留在那里。下面的代码仅缩放按钮,而不更改其位置。
package com.dynamic;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.dynamic.R;
import com.dynamic.R.layout;
public class dy extends Activity {
int status;
private FrameLayout layout;
ImageView image;
Button b;
LayoutParams params;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frm);
final Button tv=(Button)findViewById(R.id.txt_birth);
tv.setDrawingCacheEnabled(true);
layout = (FrameLayout) findViewById(R.id.frm);
params = new LayoutParams(100,100);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tv.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent me) {
// TODO Auto-generated method stub
if (me.getAction() == MotionEvent.ACTION_DOWN) {
System.out.println("up");
status = 0;
}
if (me.getAction() == MotionEvent.ACTION_UP) {
status = 1;
//Log.i("Drag", "Stopped Dragging");
} else if (me.getAction() == MotionEvent.ACTION_MOVE) {
if (status == 0) {
System.out.println("Dragging");
tv.setPadding((int) me.getRawX(), (int) me.getRawY(), 0, 0);
// b.setPadding(0,50,0,0);
tv.invalidate();
}
}
return false;
}
});
}
}