Android 在自定义视图中显示广告横幅

Android 在自定义视图中显示广告横幅,android,ads,appodeal,Android,Ads,Appodeal,我有一个自定义的查看活动,我想在其中显示一个广告。屏幕底部只有一个横幅视图。我正在使用Appodeal的API做广告。 以下是我迄今为止所做的尝试: public class main extends AppCompatActivity { BannerView bannerView; View customView; public static void loadAd(Context context, Activity activity) {

我有一个自定义的查看活动,我想在其中显示一个广告。屏幕底部只有一个横幅视图。我正在使用Appodeal的API做广告。 以下是我迄今为止所做的尝试:

public class main extends AppCompatActivity  {

    BannerView bannerView;
    View customView;

    public static void loadAd(Context context, Activity activity) {
            Appodeal.setTesting(true);
            Appodeal.disableNetwork(context, "cheetah");
            Appodeal.disableLocationPermissionCheck();
            Appodeal.setBannerViewId(R.id.appodealBannerView);
            Appodeal.initialize(activity, context.getString(R.string.app_key), Appodeal.BANNER_VIEW);
            Appodeal.show(activity, Appodeal.BANNER_VIEW);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        customView = new CustomView(this, null);
        setContentView(customView);

        bannerView = new BannerView(this, null);
        bannerView.setId(R.id.appodealBannerView);
    }

    @Override
    protected void onResume() {
        super.onResume();

        loadAd(this, this);
    }

    class CustomView extends View {
        CustomView(Context ctx, AttributeSet attrs) {
            super(ctx, attrs);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            bannerView.draw(canvas);

            invalidate();
        }
    }
}

任何帮助都将不胜感激

U可以使用如下xml布局,例如:

<RelativeLayout
 ...>
 <PathToCustomView.CustomView
  ...
  />

 <PathToBannerView.BannerView
  android:below="+id/myCustomviewId"
  ...
  />

</RelativeLayout>