需求:进度圈显示在手指点击位置
设备:平板
解决办法:将点击事件获取到的位置(MotionEvent e)与控件设置位置建立联系
在网上找了很多都没有解决问题,下面代码为自己摸索得到的解决办法,可能不实用于所有,但已解决我的需求
//view为点击的控件
view.setOnTouchListener(new DefaultMapViewOnTouchListener(mainActivity, view) {
@Override
public boolean onSingleTapConfirmed(final MotionEvent e) {
//点击事件 progressBar为进度圈
ViewGroup.LayoutParams params = MainActivity.progressBar.getLayoutParams();
ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(params);
DisplayMetrics dm = mainActivity.getResources().getDisplayMetrics();
int screenHeigth = dm.heightPixels;//获取设备的屏幕高度
marginLayoutParams.topMargin=Math.round((e.getY()-(screenHeigth/2))*dm.density);dm.density为屏幕每平方英寸中的像素数量
marginLayoutParams.leftMargin=e.getX();