gpt4 book ai didi

Android onTouch 监听器事件

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:34 26 4
gpt4 key购买 nike

我正在使用 ontouch 事件,但我遇到的问题是它调用了 down 事件,但它没有调用 move 事件或 UP 事件检查以下代码

public class DragNewActivity extends Activity implements OnTouchListener  {

private float X;
private float Y;
private int width;
private int height;
private CharSequence s;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Log.d("D","D");

TextView tv1 = (TextView)findViewById(R.id.tv1);
TextView tv2 = (TextView)findViewById(R.id.tv2);
tv1.setOnTouchListener(this);
//tv2.setOnTouchListener(this);
}

@Override
public boolean onTouch(View v, MotionEvent event) {

//int action = event.getAction();
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Log.d("DOWN","DOWN");
break;

case MotionEvent.ACTION_MOVE:
Log.d("MOVE","MOVE");
break;

case MotionEvent.ACTION_UP:
Log.d("UP","UP");
X = event.getRawX();
Y = event.getRawY();

Display display = getWindowManager().getDefaultDisplay();
width=display.getWidth()/2;
height=display.getHeight()/2;
Log.e("X", X+"");
Log.e("Y", Y+"");
Log.e("ScX", width+"");
Log.e("ScY", height+"");
if(X>width && Y>height){
Log.e("SUFI", "Event ho gyuaaaaaaa");
}

break;
}
return false;
}
}

最佳答案

不要从ontouch 返回false 返回true 以便它会监听下一个 Action 事件

关于Android onTouch 监听器事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8356283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com