Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-在Android服务内的onClick上移动带有动画的ImageView_Android - Fatal编程技术网

Android-在Android服务内的onClick上移动带有动画的ImageView

Android-在Android服务内的onClick上移动带有动画的ImageView,android,Android,我无法在Android中的服务中移动ImageView。此图像视图是使用windowManager添加的。我想将其移动到0,0或屏幕左上方 你的问题不清楚,为什么在服务中会有图像视图?我将它们添加到服务中,这样即使活动退出,它们也可以留在屏幕上。但图像视图是在活动中绘制的,对吗?还有,在活动完成后仍显示图像的原因是什么?服务中也没有绘制图像视图。代码imageView=新ImageViewthis;imageView.setImageResourceR.drawable.head;final W

我无法在Android中的服务中移动ImageView。此图像视图是使用windowManager添加的。我想将其移动到0,0或屏幕左上方


你的问题不清楚,为什么在服务中会有图像视图?我将它们添加到服务中,这样即使活动退出,它们也可以留在屏幕上。但图像视图是在活动中绘制的,对吗?还有,在活动完成后仍显示图像的原因是什么?服务中也没有绘制图像视图。代码imageView=新ImageViewthis;imageView.setImageResourceR.drawable.head;final WindowManager.LayoutParams params=新建WindowManager.LayoutParams WindowManager.LayoutParams.WRAP_内容,WindowManager.LayoutParams.WRAP_内容,WindowManager.LayoutParams.TYPE_电话,WindowManager.LayoutParams.FLAG_不可聚焦,像素格式.半透明;params.gravity=gravity.TOP | gravity.LEFT;参数x=0;参数y=0;windowManager.addViewimageView,参数;Code和ImageView被添加到服务中,以便用户可以在活动退出后使用它。它将作为一个图标留在屏幕上。
imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                int[] locations = new int[2];
                imageView.getLocationOnScreen(locations);
                int left = locations[0];
                int top = locations[1];

                Toast.makeText(getApplicationContext(), "left: "+left+" top: "+top, 
                        Toast.LENGTH_SHORT).show();

                TranslateAnimation animation = new TranslateAnimation(left, 10, top,10);
                animation.setDuration(1000);
                animation.setFillAfter(false);

                imageView.startAnimation(animation);

            }});