当前位置:网站首页>直播源码开发,各种常见的广告形式
直播源码开发,各种常见的广告形式
2022-08-03 20:17:00 【云豹网络科技】
直播源码开发,各种常见的广告形式
一.横幅式广告
编程方式创建广告布局
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/adMobView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化广告
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//用编程的方式创建布局加载读取广告
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
mAdView = new AdView(this);
mAdView.setAdSize(AdSize.BANNER);
//mAdView.setAdSize(new AdSize(300,50));
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111(测试横幅广告ID)");
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
layout.addView(mAdView);
mAdView.loadAd(adRequestBuilder.build());
setContentView(layout);
//广告事件
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
//广告完成加载时要执行的代码。
Toast.makeText(getApplicationContext(), "Admob广告加载成功!", Toast.LENGTH_LONG).show();
}
@Override
public void onAdFailedToLoad(LoadAdError adError) {
// 当广告请求失败时要执行的代码。
Toast.makeText(getApplicationContext(), "Admob广告加载失败!", Toast.LENGTH_LONG).show();
}
@Override
public void onAdOpened() {
// 当广告打开叠加层时要执行的代码
// 覆盖屏幕。
}
@Override
public void onAdClicked() {
// 当用户点击广告时执行的代码。
}
@Override
public void onAdClosed() {
// 用户即将返回时执行的代码
// 点击广告后进入应用程序。
}
});
}
二.插页广告
activity_two.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TwoActivity"
tools:ignore="MergeRootFrame">
<TextView
android:id="@+id/game_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/impossible_game"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/game_title"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/retry_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="重试"
app:backgroundTint="#009688" />
</RelativeLayout>
以上就是直播源码开发,各种常见的广告形式, 更多内容欢迎关注之后的文章
边栏推荐
猜你喜欢

高并发,你真的理解透彻了吗?

倒计时2天,“文化数字化战略新型基础设施暨文化艺术链生态建设发布会”启幕在即

Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)

那些年我写过的语言

Alexa染料标记RNA核糖核酸|RNA-Alexa 514|RNA-Alexa 488|RNA-Alexa 430

tRNA-m5C转运RNA(tRNA)修饰5-甲基胞嘧啶(m5C)|tRNA修饰m1Am2A (2-methyladenosine)

调用EasyCVR云台控制接口时,因网络延迟导致云台操作异常该如何解决?

化算力为战力:宁夏中卫的数字化转型启示录

【飞控开发高级教程6】疯壳·开源编队无人机-AI语音控制

调用EasyCVR接口时视频流请求出现404,并报错SSL Error,是什么原因?
随机推荐
leetcode 231. 2 的幂
YARN功能介绍、交互流程及调度策略
【HiFlow】经常忘记签到怎么办?使用腾讯云场景连接器每天提醒你。
Leetcode 125. Verify palindrome string
使用 ReportLab 绘制 PDF
详解AST抽象语法树
Internet Download Manager简介及下载安装包,IDM序列号注册问题解决方法
Detailed AST abstract syntax tree
边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型
一种能有效缓解环境噪声对音频质量干扰的方案
LeetCode 899. 有序队列
后台图库上传功能
高位套牢机构,用友网络的信任危机是如何产生的?
The sword refers to Offer II 044. The maximum value of each level of the binary tree-dfs method
Node version switching tool NVM and npm source manager nrm
Auto.js脚本程序打包
149. The largest number on a straight line, and check the set
matplotlib画polygon, circle
华为设备配置VRRP负载分担
涨薪5K必学高并发核心编程,限流原理与实战,分布式计数器限流