问题
I want to use AdMob and ActionBarSherlock in the same android aplication, but I don't manageto put AdMob on the top of my screen (above Sherlock ActionBar).
Anyone had some similar problems? Does anyone knows about some workaround?
Thanks.
My general layout:
<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.....
My admob layout:
<?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"/>
回答1:
I'm using ActionBarSherlock as wrapper and the following puts the ad above the action bar:
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);
}
来源:https://stackoverflow.com/questions/12255602/getting-admob-above-actionbarsherlock