我有一个包含不同部分的大图。我想要的是当用户触摸ImageView的不同部分时,应该打开不同的PopUps。例如,看到以下图片:弹出式窗口可以在Imageview中打开
在此图像中,我要的是,当用户点击第一个广场,弹出1应该开放,在广场2弹出窗口应打开。如何实现这个请。? 此外,我希望ImageView仍然是缩放和平移启用。请帮忙。
我有一个包含不同部分的大图。我想要的是当用户触摸ImageView的不同部分时,应该打开不同的PopUps。例如,看到以下图片:弹出式窗口可以在Imageview中打开
在此图像中,我要的是,当用户点击第一个广场,弹出1应该开放,在广场2弹出窗口应打开。如何实现这个请。? 此外,我希望ImageView仍然是缩放和平移启用。请帮忙。
你好,你可以关注我的这篇文章。我想,我的回答将帮助你::
popup window from android options menu not working
对你,我编辑的代码。你可以按照这种方式。如果按钮将图片,并与替换按钮:
里面的onCreate()
Button btn1=(Button) findViewById(R.id.btn1);
Button btn2=(Button) findViewById(R.id.btn2);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
initiatePopupWindow1();
}
})
btn2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
initiatePopupWindow2();
}
})
的onCreate()外
private PopupWindow pwindo1,pwindo2;
private void initiatePopupWindow1() {
try {
// We need to get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) PopupActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup,(ViewGroup)
findViewById(R.id.popup_element));
pwindo1 = new PopupWindow(layout, 350, 350, true);
pwindo1.showAtLocation(layout, Gravity.CENTER, 0, 0);
btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
btnClosePopup.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initiatePopupWindow2() {
try {
// We need to get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) PopupActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup,(ViewGroup)
findViewById(R.id.popup_element));
pwindo2 = new PopupWindow(layout, 350, 350, true);
pwindo2.showAtLocation(layout, Gravity.CENTER, 0, 0);
btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
btnClosePopup.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
可以使用(虽然似乎是不实际上你试图达到的最好的方式,但你仍然可以有一个单一的形象)
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
和在event.getX()和event.getY()会给你所在的坐标你点击
例如
if(event.getX() == 100 and event.getY() == 100)
{ // show your popup}
但是如果你有多个图像 你要知道会有一个问题在这些盒子将出现在什么位置,并且您可能会遇到问题,如果图像要放大
请检查我编辑的答案 –