- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
4 年多以来,我们一直在我们的 Android 应用程序中使用 AdMob。在过去的几天里,我们在没有修改任何代码的情况下遇到了 AdMob 的问题。
如下图所示:
===
下面是我们实现的描述:
我们将横幅广告放置在 fragment 屏幕顶部约 20% 的位置,在 LinearLayout“banner_container”内
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
....
<LinearLayout android:id="@+id/banner_container"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
....
</LinearLayout>
在 Fragment 的“onCreateView”上,我们将横幅添加到容器中
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
adView = new AdView(getActivity());
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
LinearLayout mBannerContainer = rootView.findViewById(R.id.banner_container);
mBannerContainer.setVisibility(View.VISIBLE);
mBannerContainer.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build();
adView.loadAd(adRequest);
...
}
===
我们如何恢复到加载时横幅空间已被预留的情况?
最佳答案
由于 Admob 在加载横幅之前不会保留横幅高度,因此解决方案似乎是手动完成。
Smart Banners are ad units that will render screen-wide banner ads on any screen size across different devices in either orientation. Smart Banners help deal with increasing screen fragmentation across different devices by "smartly" detecting the width of the phone in its current orientation, and making the ad view that size.
Three ad heights (in dp, density-independent pixel) are available:
32 - used when the screen height of a device is less than 40050 - used when the screen height of a device is between 400 and 72090 - used when the screen height of a device is greater than 720
解决方案一
您可以使用以下方法知道高度:
public static int getAdViewHeightInDP(Activity activity) {
int adHeight = 0;
int screenHeightInDP = getScreenHeightInDP(activity);
if (screenHeightInDP < 400)
adHeight = 32;
else if (screenHeightInDP >= 400 && screenHeightInDP <= 720)
adHeight = 50;
else
adHeight = 90;
return adHeight;
}
public static int getScreenHeightInDP(Activity activity) {
DisplayMetrics displayMetrics = ((Context) activity).getResources().getDisplayMetrics();
float screenHeightInDP = displayMetrics.heightPixels / displayMetrics.density;
return Math.round(screenHeightInDP);
}
在您的“banner_container”中删除:
android:visibility="gone"
更改 fragment “onCreateView”:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
adView = new AdView(getActivity());
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
LinearLayout mBannerContainer = rootView.findViewById(R.id.banner_container);
mBannerContainer.setLayoutParams(
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
getAdViewHeightInDP(this.getActivity())
));
)
mBannerContainer.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build();
adView.loadAd(adRequest);
...
}
方案二
不使用方法“getAdViewHeightInDP”和“getScreenHeightInDP”,而是使用方法“AdSize.SMART_BANNER.getHeightInPixels (this)”。
在您的“banner_container”中删除:
android:visibility="gone"
更改 fragment “onCreateView”:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
adView = new AdView(getActivity());
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
LinearLayout mBannerContainer = rootView.findViewById(R.id.banner_container);
mBannerContainer.setLayoutParams(
new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
AdSize.SMART_BANNER.getHeightInPixels(this.getActivity())
));
)
mBannerContainer.addView(adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build();
adView.loadAd(adRequest);
...
}
关于android - Android 上的 Admob : banner space not reserved before loading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53166028/
如何在 azure (acs-engine) 中设置保留资源,无需 ssh 集群(仅使用 kubectl 命令)? 最佳答案 使用kubectl使用命令行工具来实现您的目标是不可行的,因为它仅向 ap
我正在尝试在 FreeBSD 机器上启动并运行 Artifactory。我安装了/usr/ports/devel/artifactory,似乎没有问题,然后运行“/usr/local/etc/rc.d
我经常遇到这样的情况,我知道 std::vector 在完成工作后将包含最大数量的元素;让我们说 10000。但是它可以很容易地包含更少的元素,例如 100。无法判断有多少元素得到 .emplaced
我正在做一些测试来测量标准容器在各种条件下的性能,我遇到了一些奇怪的事情。当我在 std::vector 的中间插入许多项目时,如果我首先使用要添加的元素的确切数量调用 reserve,我发现在大多数
这是我正在操作的更新查询。此处错误“set data = :updateValue”,数据是 Dynamo DB 的保留关键字。我想我应该在这里使用 update ExpressionAttribut
假设我们有一个创建并使用可能很大的vector的方法。 已知最大元素数为maxElems。 据我所知,C++ 11的标准实践是: vector fooVec; fooVec.reserve(maxEl
假设我必须编写一个 C 或 C++ 计算密集型函数,该函数有 2 个数组作为输入,一个数组作为输出。如果计算使用 2 个输入数组的频率高于它更新输出数组的频率,我最终会遇到输出数组很少被缓存的情况,因
所附代码包含对 std::vector::assign() 的三个调用。在第一次调用之前,调用 std::vector::reserve() 来分配适当的内存量,然后填充向量。对 allocate()
我认为我可以学习和改进编程的最好方法之一就是查看各种源代码。我正在查看 Blender 的源代码并注意到有关头文件的一些信息。大部分都用过#ifndef包括守卫,其中宏被双下划线包围(例如 __BME
我对这个保留 key 有点困惑,并且案例导致了错误。这是导致错误的示例代码。 var sample = { init: function() { this.sampleFunc
什么时候适合使用string::reserve?我意识到它用于为字符串保留一定数量的字符,但这有什么用呢?如果你过去了,字符串还会调整大小吗?它会提高效率吗? 最佳答案 它将“保留”指定的空间以减少重
有可能已预订或未预订的房间。预订时间为从(日期)到(日期)为止。人员按日期搜索房间:from_field 和til_field。正在尝试查找是否有可用房间。 SELECT rooms.* FROM r
这个问题在这里已经有了答案: Choice between vector::resize() and vector::reserve() (4 个答案) Why can't you access m
我正在尝试将其合并为一个查询。 预订系统有2个表,酒店和预订。 hotels(id, num_rooms) reservations(hotel_id, start_date, end_date) (
我必须为酒店设计和实现预订系统。我有 预订对象的数组列表 房间对象的数组列表 我想在指定日期“预订”房间。 预订没有日期的房间很容易,但日期部分却让事情变得复杂。我正在为此设计而苦苦挣扎,并且有信心朝
正在阅读来自 What are the rules about using an underscore in a c identifier 的答案我偶然发现了以下引文: From the 2003 C
我需要构建一个数据库和服务,我有需要交付给用户的资源。并且交付需要一些时间或需要用户做更多的工作。 这些是我存储信息的表。 Table - Description ________________
BitmapData 有一个名为 Reserved 的属性,它返回一个 32 位 signed integer。 Microsoft 的文档说不要使用此属性。如果我们不应该使用它;那它为什么在那里?它
让我们 std::vector myVec; myVec.reserve(10); 如果我只分配了 5 个元素,我怎样才能重新获得为其他 5 个元素分配的内存? 最佳答案 std::vector v
我正在尝试做这样的事情: #include #include int main() { int l[] = {1,2,3,4}; vector vi(4); copy(l,
我是一名优秀的程序员,十分优秀!