0

我在布局中放置了一些圆形图像,当用户将鼠标悬停在它们上或触摸图像时,我想显示内容。我试图在谷歌上搜索,但我发现这个主题没有任何用处。

当用户将鼠标悬停在图像上时,我想显示(即在test1图像上)一个带有一些文本和一个或两个按钮的小窗口(如弹出窗口)。

有可能在Android中做到这一点吗?

编辑:这是我想要达到的结果。例如,在这种情况下,当用户悬停或触摸图像时,会出现一个弹出窗口并显示附加选项。

在此处输入图像描述

        // Draw circles
    canvas.drawCircle((canvas.getWidth()/2)-300, canvas.getHeight()/2,60,paint);
    canvas.drawCircle((canvas.getWidth()/2), (canvas.getHeight()/2)-300,60,paint);
    canvas.drawCircle((canvas.getWidth()/2)+300, (canvas.getHeight()/2),60,paint);

    // load bitmap..
    Bitmap test = BitmapFactory.decodeResource(this.getResources(), R.drawable.img1);
    Bitmap test1 = MLRoundedImageView.getCroppedBitmap(test, 160);
    canvas.drawBitmap(test1, 468, 525, paint);
4

1 回答 1

1

这不是确切的解决方案,但我认为 popupmenu 适用于此

PopupMenu popup = new PopupMenu(context, view_anchor);
popup.inflate(R.menu.your_menu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                                case R.id.button1:
                                    //code when button1 is clicked
                                    popup.dismiss();
                                    break;
                                case R.id.button2:
                                    //code when button2 is clicked
                                    popup.dismiss();
                                    break;
                            }
                            return false;
                        }
                    });
popup.show();

将上面的代码放在你的图片中 onclicklistener

将 onclicklistener 放入您的图片中

ImageView image1, image2;

in oncreate
image1 = (ImageView) findViewById(R.id.id_of_image1);
image1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //popup code
                        }
                    });

然后在xml中为您的imageview添加一个id

<ImageView
android:id="@+id/id_of_image1"
/>
于 2016-12-27T00:36:02.140 回答