定义一个popupwindow,如下:
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View imageControlView = inflater.inflate(R.layout.imagectl, null);
imageControl = new PopupWindow(imageControlView,
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
slideshow = (ImageButton1) imageControlView
.findViewById(R.id.playasslide);
slideshow.setOrientation(LinearLayout.VERTICAL);
slideshow.setImage(R.drawable.icon_play);
slideshow.setText(getResources().getString(R.string.slideshow));
imageControl.setOutsideTouchable(true);
imageControl.update();
其中ImageButton1是自定义的一个类,代码如下:
public class ImageButton1 extends LinearLayout {
private ImageView mImage;
private TextView mText; public ImageButton1(Context context, AttributeSet attrs) {
super(context, attrs);
mImage = new ImageView(context, attrs);
mImage.setPadding(0, 0, 0, 0);
mText = new TextView(context, attrs);
mText.setGravity(android.view.Gravity.CENTER);
mText.setTextColor(Color.rgb(256, 256, 256));
mText.setPadding(5, 0, 0, 0);
setClickable(true);
setBackgroundResource(R.drawable.imgcontrolbg);
setOrientation(LinearLayout.HORIZONTAL);
addView(mImage);
addView(mText);
setFocusable(false);
} public void setImage(int id) {
this.mImage.setImageResource(id);
} public void setText(String text) {
this.mText.setText(text);
}Activity监听双击事件弹出popupwindow:
public boolean onDoubleTap(MotionEvent e) {
if (!imageControl.isShowing()) {
imageControl.showAtLocation(
view,
Gravity.CENTER_VERTICAL, 0, 0);
} else
imageControl.dismiss();
return true;
}
问题是popupwindow弹出来后,Activity(主要是一个ImageSwitcher)监听不到Touch事件了。如下图所示,黑色框内表示屏幕,蓝色区域是popupwindow,弹出来后,蓝线框内就接受不到Touch事件了,蓝线框外还是可以监听的到的。在网上找了很多方法,都没成功。请问哪位知道问题出在哪里啊,我希望整个屏幕都能监听到Touch事件。