मैं ड्रैग और ड्रॉप बटन बनाना चाहता हूं। इसे खींचें जहां आप इसे करना चाहते हैं और यह वहां रहता है। कोड के नीचे केवल बटन स्केल करता है, इसकी स्थिति नहीं बदलता है।एंड्रॉइड में ड्रैग एंड ड्रॉप बटन कैसे बनाएं
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;
}
});
}
}
मैं इस कोशिश की, लेकिन जैसा कि मैंने ले जाते हैं, imag/बटन भी कम है और अदृश्य होता जा रहा है। क्या आप – png
मदद कर सकते हैं मैं रिश्तेदार लेआउट का उपयोग कर रहा था। यही कारण था। धन्यवाद – png
मैं रिलेटिव लेआउट का भी उपयोग कर रहा हूं, कृपया मेरी मदद करें कि आपको यह –