首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在自定义视图中显示广告横幅

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

Stack Overflow用户
提问于 2017-08-07 04:12:41
回答 1查看 332关注 0票数 0

我有一个自定义视图活动,我想在其中显示一个广告。只是在屏幕底部的横幅视图。我正在使用Appodeal的API来做广告。这是我到目前为止尝试过的:

代码语言:javascript
运行
复制
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();
        }
    }
}

任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-07 04:24:22

你可以像下面这样使用xml布局,例如:

代码语言:javascript
运行
复制
<RelativeLayout
 ...>
 <PathToCustomView.CustomView
  ...
  />

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

</RelativeLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45536184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档