android - 横向时 Admob 横幅部分覆盖全屏视频
问题描述
如何在我的 kotlin 代码中定义垂直线性布局,以便视图不会在横幅和其他内容之间重叠?
问题是admob广告在横向时会覆盖视频播放器内容
这在我的程序中
override fun onShowCustomView(view: View, callback: CustomViewCallback, requestedOrientation: Int) {
val currentTab = tabsManager.currentTab
if (customView != null) {
try {
callback.onCustomViewHidden()
} catch (e: Exception) {
logger.log(TAG, "Error hiding custom view", e)
}
return
}
try {
view.keepScreenOn = true
} catch (e: SecurityException) {
logger.log(TAG, "WebView is not allowed to keep the screen on")
}
originalOrientation = getRequestedOrientation()
customViewCallback = callback
customView = view
//setRequestedOrientation(requestedOrientation)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
val decorView = window.decorView as FrameLayout
fullscreenContainerView = LayoutInflater.from(this).inflate(R.layout.layout_fullscrren_video, null) as LinearLayout
fullscreenContainerView?.setBackgroundColor(ContextCompat.getColor(this, R.color.black))
if (view is FrameLayout) {
val child = view.focusedChild
if (child is VideoView) {
videoView = child
child.setOnErrorListener(VideoCompletionListener())
child.setOnCompletionListener(VideoCompletionListener())
}
} else if (view is VideoView) {
videoView = view
view.setOnErrorListener(VideoCompletionListener())
view.setOnCompletionListener(VideoCompletionListener())
}
decorView.addView(fullscreenContainerView, COVER_SCREEN_PARAMS)
fullscreenContainerView?.addView(customView, 0, LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0).also { it.weight = 1f })
fullscreenContainerView?.findViewById<AdView>(R.id.ad_view)?.let { AdsManager.get.initAdView(it) }
decorView.requestLayout()
setFullscreen(enabled = true, immersive = true)
currentTab?.setVisibility(INVISIBLE)
}
myxml代码
layout_fullscreen_video.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
include layout="@layout/layout_ad_banner"
</LinearLayout>
这是我的 layout_ad_banner
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/banner_ad_unit_id" />
</FrameLayout>
解决方案
不要在横向模式下加载广告横幅,并在横向模式下单独布局没有广告横幅。
推荐阅读
- python - 在 python 循环中运行 bash 命令
- python-3.x - 在训练顺序张量流和 keras 模型中记录时间步长
- mysql - MySQL - 选择匹配所有值的记录
- c - 使用一个目标文件,该目标文件正在使用新内核上的新内核删除的内核函数?
- python - 根据 Pandas 中列的内容将列拆分为多列
- javascript - Google Chart not 100% of div width - 包含事件侦听器以从代理表重绘图表
- javascript - Javascript cloneNode innerText 不读取
为 \n - macos - DriverKit 是否适用于自定义 USB 设备来控制麦克风音量(无流)?
- encryption - 您可以使用以太坊密钥进行 Web 身份验证 (WebAuthn)
- java - 在 MAC m1 上运行 sqlcmd 会引发错误“dyld:未加载库:/usr/local/lib/libodbc.2.dylib”