问题描述
我有一个想法,当成员触摸到我必须登录用户的相同位置时,以密码作为图像触摸位置来实现登录。任何人都可以帮助我如何实现它,我只能获得屏幕的位置。 而且即使我触摸相同的位置,x和y坐标也会发生变化。
1楼
我会说创建一个扩展ImageView的自定义视图:
public class PasswordView extends ImageView {
public PasswordView(Context context) {
super(context);
// Any additional PasswordView setup
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float xTouchPos = event.getX();
float yTouchPos = event.getY();
// If the PasswordView was clicked
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Check if they touched in the secret spot
}
return super.onTouchEvent(event);
}
}
通过子类化ImageView ,您仍然可以访问ImageView的所有标准功能(设置图像源等),并且还可以添加其他功能来检查用户的触摸位置。
使用onTouchEvent
。