popupwindow를 확장 한 클래스를 만들었습니다.안드로이드 Click through PopupWindow
private OnTouchListener onTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
Log.d(TAG, "Received");
if (Math.pow(x - coordinates[0], 2) + Math.pow((y - coordinates[1]), 2) < Math.pow(radius, 2)) {
Log.d(TAG, "bubbled through");
return false;
}
return true;
}
};
실제로, 나는 시각적으로 표현 SomePopupWindow.showAtLocation(SomeActivity.getWindow().getDecorView().getRootView(), Gravity.CENTER, 0, 0);
를 호출 popupwindow를 표시, 여기에 문제의 제품입니다 : 생성자는이 다음 onTouchListener의 모습을 다음
super(builder.context.get());
this.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
setFocusable(true);
setBackgroundDrawable(new BitmapDrawable());
setTouchInterceptor(onTouchListener);
FrameLayout frameLayout = new FrameLayout(builder.context.get());
LayoutInflater inflater = (LayoutInflater) builder.context.get().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
View overlayBase = inflater.inflate(R.layout.tutorial_view_items, null, false);
frameLayout.addView(builder.backgroundView);
frameLayout.addView(overlayBase);
setContentView(frameLayout);
과 같이 보입니다
touchListener가 응답하지만 입력이 기본 액티비티 또는 popupwindow로 전송되지 않습니까? (버튼이 응답하지 않는 경우, ontouchlistener를 제거한 것처럼 버튼이 제대로 작동합니다.) FrameLayout이 터치 리스너 (이 경우 popupwindow의 즉 내용보기) 대신 popupwindow 자체를 설정
갱신 나 팝업에 정의 된 버튼을 클릭 할 수 있습니다. 여전히 Popupwindow에 대한 터치 인터셉터를 등록 기본 활동 /보기
솔루션
에 터치 이벤트를 위임하는 방법을 찾고. 액티비티를 처리하기를 원할 경우 팝업 창에서 터치를 처리하기를 원할 경우 someActivity.dispatchTouchEvent(someMotionEventPassedIntoTheTouchIntercepter);
으로 전화를 걸면 팝업 창 setContentView(someView)
메서드에 설정된대로 팝업 창 내용보기 으로 someView.dispatchTouchEvent(theMotionEventPassedToTouchInterceptor)
으로 전화하십시오.
내 방법은 특별히 당신을 도울 수 있습니다이 코드를하려고 다음
private OnTouchListener onTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
if (Math.pow(x - coordinates[0], 2) + Math.pow((y - coordinates[1]), 2) < Math.pow(
radius, 2)) {
activity.get().dispatchTouchEvent(event);
return false;
}
frameLayout.dispatchTouchEvent(event);
return true;
}
};
처럼 보였다? – NameSpace
예, 혼란에 대해 사과드립니다. ontouchlistener가 호출되고 내가 터치 한 부분에 따라 로그 출력이 따라옵니다 (즉 원 영역을 터치하면 "버블이 통과 함") – rperryng
확실하지 않습니다. 해킹 솔루션이 필요한 경우 터치가 xy 좌표에 있는지 확인하고 performClick()을 수행 할 수 있습니다.또는 버튼이 포함 된 Activity/View의 onTouch에 명시 적으로 터치를 전달하십시오. 잘만되면 누군가는 유창한 대답을 줄 수 있습니다. – NameSpace