2012-09-04 45 views
4

我想使用AdMob和ActionBarSherlock在同一臺Android aplication,但我不manageto把AdMob將在我的屏幕頂部(以上夏洛克動作條)。入門的AdMob上述actionbarsherlock

任何人都有類似的問題?有誰知道一些解決方法?

謝謝。

我的總體佈局:

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

回答

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); 
} 
+0

我還沒有找到它在Android ActionBar中的構建方式。你知道一個方法嗎?這可能與Android的ActionBar問題:http://stackoverflow.com/questions/17258323/how-to-place-admob-at-the-top-of-the-screen-above-android-actionbar –