Я хочу задать вопрос:
Я использовал код MotionEvent, чтобы перетащить кнопку для игры в вопрос и ответ. Я работаю над ней, дело в том, что я не могу нажать на перетаскиваемый файл.После того, как я начал перетаскивать ее, кнопка выглядит так, как будто она всегда остается в ACTION_DOWN, я тоже попробовал действия ОТМЕНА и ВВЕРХ, но все же тоже самое!другая кнопка или элемент (как я хочу, чтобы он обнаруживал прикосновение других элементов), например, когда перетаскиваемая кнопка [btn1] касается другой кнопки [btn2], она изменит цвет, например !!
3 проблемы:
любое предложение, как это исправить плз!и ты заранее
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import android.app.Activity;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Button;
import java.util.Timer;
import java.util.TimerTask;
import android.view.View;
public class MainActivity extends Activity {
private Timer _timer = new Timer();
private double res = 0;
private double lvl = 0;
private String message = "";
private LinearLayout linear3;
private TextView textview13;
private LinearLayout linear11;
private LinearLayout linear13;
private LinearLayout linear12;
private LinearLayout linear8;
private Button button1;
private TextView textview14;
private Button button4;
private Button button2;
private Button button3;
private TimerTask m;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize();
initializeLogic();
}
private void initialize() {
linear3 = (LinearLayout) findViewById(R.id.linear3);
textview13 = (TextView) findViewById(R.id.textview13);
linear11 = (LinearLayout) findViewById(R.id.linear11);
linear13 = (LinearLayout) findViewById(R.id.linear13);
linear12 = (LinearLayout) findViewById(R.id.linear12);
linear8 = (LinearLayout) findViewById(R.id.linear8);
button1 = (Button) findViewById(R.id.button1);
textview14 = (TextView) findViewById(R.id.textview14);
button4 = (Button) findViewById(R.id.button4);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button1.setOnTouchListener(new OnTouchListener() {
PointF DownPT = new PointF();
PointF StartPT = new PointF();
@Override public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
button1.setX((int)(StartPT.x+mv.x));
button1.setY((int)(StartPT.y+mv.y));
StartPT = new PointF(button1.getX(), button1.getY());
break;
case MotionEvent.ACTION_DOWN : DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(button1.getX(), button1.getY());
break;
case MotionEvent.ACTION_UP :
break;
default : break;
}
return true;
}
});
textview13.setText(message);
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
button1.setBackgroundColor(0xFFCFD8DC);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
private void initializeLogic() {
/**
android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable();
gd.setCornerRadius(30);**/
/* radius */
/*gd.setStroke(4, Color.WHITE);*/
/* stroke heigth and color */
m = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
lvl = 1;
textview14.setText("من هو مستر صلصا ؟");
button2.setText("مدير قناة صلصا");
button3.setText("صاحب سلسلة \nألف ليلة و ليلة");
button4.setText("لا أعلم");
}
});
}
};
_timer.schedule(m, (int)(1000));
m = new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if ((((SketchwareUtil.getLocationX(button1) + 75) > (SketchwareUtil.getLocationX(button2) - 120)) && ((SketchwareUtil.getLocationX(button1) - 125) < (SketchwareUtil.getLocationX(button2) + 120))) && (((SketchwareUtil.getLocationY(button1) + 130) > (SketchwareUtil.getLocationY(button2) - 60)) && ((SketchwareUtil.getLocationY(button1) - 70) < (SketchwareUtil.getLocationY(button2) + 60)))) {
res = 1;
button2.setBackgroundColor(0xFF64DD17);
}
if ((((SketchwareUtil.getLocationX(button1) + 75) > (SketchwareUtil.getLocationX(button3) - 120)) && ((SketchwareUtil.getLocationX(button1) - 125) < (SketchwareUtil.getLocationX(button3) + 120))) && (((SketchwareUtil.getLocationY(button1) + 130) > (SketchwareUtil.getLocationY(button3) - 60)) && ((SketchwareUtil.getLocationY(button1) - 70) < (SketchwareUtil.getLocationY(button3) + 60)))) {
res = 2;
button3.setBackgroundColor(0xFFF44336);
}
if ((((SketchwareUtil.getLocationX(button1) + 75) > (SketchwareUtil.getLocationX(button4) - 120)) && ((SketchwareUtil.getLocationX(button1) - 125) < (SketchwareUtil.getLocationX(button4) + 120))) && (((SketchwareUtil.getLocationY(button1) + 130) > (SketchwareUtil.getLocationY(button4) - 60)) && ((SketchwareUtil.getLocationY(button1) - 70) < (SketchwareUtil.getLocationY(button4) + 60)))) {
res = 3;
button4.setBackgroundColor(0xFFF44336);
}
}
});
}
};
_timer.scheduleAtFixedRate(m, (int)(1000), (int)(100));
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
default:
break;
}
}