-
Notifications
You must be signed in to change notification settings - Fork 91
MotionEventHelper
sloop edited this page Dec 5, 2016
·
3 revisions
MotionEvent 辅助类,帮助 MotionEvent 中的坐标执行坐标变换。
方法 | 摘要 |
---|---|
transformEvent | 使用一个 Matrix 对 MotionEvent 中的坐标进行转换。 |
public class TestMorionEventHelperActivity extends BaseActivity {
private static final String TAG = "TestMorionEventHelper";
Matrix mMatrix;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_see_logcat);
TextView text = (TextView) findViewById(R.id.custom_view_text);
text.append("\n在屏幕上触摸,查看坐标变化。\nx,y坐标均增加100");
mMatrix = new Matrix();
mMatrix.postTranslate(100,100);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i(TAG, "转换前 > "+event.getX()+" : "+event.getY());
MotionEvent e = MotionEventHelper.transformEvent(event, mMatrix);
Log.i(TAG, "转换后 > "+e.getX()+" : "+e.getY());
Log.i(TAG, "-------------------------");
return true;
}
}
结果:
TestMorionEventHelper: 转换前 > 900.4544 : 960.0
TestMorionEventHelper: 转换后 > 1000.4544 : 1060.0
TestMorionEventHelper: -------------------------
TestMorionEventHelper: 转换前 > 900.4544 : 960.0
TestMorionEventHelper: 转换后 > 1000.4544 : 1060.0
TestMorionEventHelper: -------------------------