0

我有一个admob adView设置,当然,由于最新版本中的一个错误,我需要动态创建它。

我想要屏幕底部的广告,我有一个LinearLayout设置在底部但有一个限制,否则广告将无法加载。我需要LinearLayout有一定的高度(不包装内容)

这一切都适用于测试广告,但问题是......我打算把这个布局放在一个 RelativeLayout 中,这样我就可以将它与底部对齐,但是一旦我这样做 - 我没有看到任何广告...

这是我的代码onCreate

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

    LinearLayout layout = (LinearLayout)findViewById(R.id.adView);

    layout.addView(adView);


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

正如我所说,上面的代码工作得很好,但我想在底部和relativeLayout内部对齐它,但它必须动态完成......

4

3 回答 3

0

在运行时计算显示高度并根据需要设置边距顶部。计算高度的方法

Display display = getWindowManager().getDefaultDisplay();       
        int width = display.getWidth();
于 2013-01-18T05:03:58.440 回答
0

您的线性布局应如下所示。因此您的 adview 将自动设置在页面底部。

  <LinearLayout  android:layout_width="fill_parent"
        android:layout_alignParentBottom="true" 
         android:id="@+id/rootViewGroup"
        android:layout_height="wrap_content" >
    </LinearLayout>

希望这会帮助你 。

于 2013-01-18T06:39:01.877 回答
0

这是将横幅广告放在列表视图或回收站视图下的常见布局方法。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adView">

    <FrameLayout
        android:id="@+id/fragment"
        android:name="net.yrom.screenrecorder.fragment.ItemFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout="@layout/fragment_item_list">Here Can Be anything Mostly it's list view</FrameLayout>
</RelativeLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="bottom"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_home_footer"></com.google.android.gms.ads.AdView>

于 2016-07-21T10:41:36.547 回答