本文介绍了获得AdMob的上述actionbarsherlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用AdMob的和ActionBarSherlock在同一个机器人aplication,但我不manageto把AdMob的在我的屏幕顶部(上述夏洛克动作条)。

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

感谢。

我的总体布局:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<包括布局=@布局/ AdMob的/>
< TabHost
 的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 机器人:ID =@机器人:ID / tabhost
 机器人:layout_width =match_parent
 机器人:layout_height =match_parent>
 < LinearLayout中.....
 

我的AdMob的布局:

 < XML版本=1.0编码=UTF-8&GT?;
< com.google.ads.AdView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                    的xmlns:广告=htt​​p://schemas.android.com/apk/lib/com.google.ads
                    机器人:ID =@ + ID / AD浏览报
                    机器人:layout_height =WRAP_CONTENT
                    广告:adUnitId =123456
                    广告:adSize =大旗
                    机器人:layout_width =match_parent/>
 

解决方案

我用ActionBarSherlock作为包装和下面把上述操作栏上的广告:

 私人ActionBarSherlock福尔摩斯= ActionBarSherlock.wrap(本);

@覆盖
公共无效的onCreate(包savedInstanceState)
{
    / * ...设置布局在这里... * /


    AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,deadbeefmeat);

    ViewParent parentView = appView.getParent();
    做
    {
        parentView = parentView.getParent();
    }而((parentView的instanceof的LinearLayout)!);

    ((的LinearLayout)parentView).addView(AD浏览,0);

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

//所有的setContentView方法被覆盖,因为ActionBarSherlock有权修改视图
@覆盖
公共无效的setContentView(INT layoutResID)
{
    //不要叫超强!
    sherlock.setContentView(layoutResID);
}

@覆盖
公共无效的setContentView(查看视图)
{
    //不要叫超强!
    sherlock.setContentView(视图);
}

@覆盖
公共无效的setContentView(查看视图,的LayoutParams PARAMS)
{
    //不要叫超强!
    sherlock.setContentView(查看,则params);
}
 

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"/>
解决方案

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

这篇关于获得AdMob的上述actionbarsherlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:01