gpt4 book ai didi

android - 让 admob 高于 actionbarsherlock

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:50 26 4
gpt4 key购买 nike

我想在同一个 Android 应用程序中使用 AdMob 和 ActionBarSherlock,但我无法将 AdMob 放在屏幕顶部(Sherlock ActionBar 上方)。

有人遇到过类似的问题吗?有人知道一些解决方法吗?

谢谢。

我的总体布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="@layout/admob"/>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout.....

我的 admob 布局:

<?xml version="1.0" encoding="utf-8"?>
<com.google.ads.AdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_height="wrap_content"
ads:adUnitId="123456"
ads:adSize="BANNER"
android:layout_width="match_parent"/>

最佳答案

我使用 ActionBarSherlock 作为包装器,下面将广告放在操作栏上方:

private ActionBarSherlock sherlock = ActionBarSherlock.wrap(this);

@Override
public void onCreate(Bundle savedInstanceState)
{
/* ... set up layout here ... */


adView = new AdView(this, AdSize.BANNER, "deadbeefmeat");

ViewParent parentView = appView.getParent();
do
{
parentView = parentView.getParent();
} while(!(parentView instanceof LinearLayout));

((LinearLayout)parentView).addView(adView, 0);

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(adRequest);
}

// All setContentView methods are overridden because ActionBarSherlock has to modify the view
@Override
public void setContentView(int layoutResID)
{
// Don't call super!
sherlock.setContentView(layoutResID);
}

@Override
public void setContentView(View view)
{
// Don't call super!
sherlock.setContentView(view);
}

@Override
public void setContentView(View view, LayoutParams params)
{
// Don't call super!
sherlock.setContentView(view, params);
}

关于android - 让 admob 高于 actionbarsherlock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12255602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com