获得AdMob的上述actionbarsherlock(Getting admob above ac

2019-09-22 03:11发布

我想使用AdMob和ActionBarSherlock在同一台Android aplication,但我不manageto把AdMob将在我的屏幕(以上福尔摩斯动作条)的顶部。

任何人有一些类似的问题? 有谁知道一些解决方法吗?

谢谢。

我的总体布局:

<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"/>

Answer 1:

我使用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);
}


文章来源: Getting admob above actionbarsherlock