有同样的问题,似乎这是 Facebook 的 SDK 中公认的错误:
https ://developers.facebook.com/bugs/158853171214759/
Facebook 员工的最新回应是:
在与工程团队进行调查后,我们决定此时不发布针对此特定问题的修复程序。但是,我们有一些计划中的更改应该会在 SDK 的未来版本中缓解此问题。
谢谢,脸书。
更新
我能够通过创建一个自定义 FrameLayout 来检测它的点击来解决它,它很hacky,并不完美,但总比没有好。
public class AdContainer extends FrameLayout implements OnGestureListener {
GestureDetector clickDetector;
private NativeAd ad;
private AdListener listener;
public AdContainer(@NonNull Context context) {
super(context);
init();
}
public AdContainer(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public AdContainer(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@TargetApi(VERSION_CODES.LOLLIPOP)
public AdContainer(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
clickDetector = new GestureDetector(getContext(), this);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
clickDetector.onTouchEvent(ev);
return super.onInterceptTouchEvent(ev);
}
public void setAd(NativeAd ad, AdListener listener) {
this.ad = ad;
this.listener = listener;
}
// OnGestureListener
@Override
public boolean onSingleTapUp(MotionEvent e) {
Log.d("AdContainer", "detected a click in an ad container: " + ad);
if ((ad != null) && (listener != null)) {
listener.onAdClicked(ad);
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
}
像这样使用它:
(1)将您的广告布局膨胀到新的容器类中:
<com.example.AdContainer
android:id="@+id/ad_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
(2)将您的广告绑定到布局时,将其注册到AdContainer
:
AdContainer container = (ViewGroup) findViewById(R.id.ad_container);
container.setAd(ad, this); // make sure the current class implements AdListener