如何在广告的底部放置广告

时间:2013-12-01 06:46:30

标签: android admob

我希望我的adob广告出现在我的布局底部,但它显示在我的按钮下方。我需要它远离按钮我需要使用relativelayout或我可以使用线性布局任何想法如何我可以提前做到这一点感谢。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/mainLay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Main" >

    <!-- this is a lable to tell the user to input the recipients number in the input box below -->

    <TextView
        android:id="@+id/tvNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/number" />

    <!-- this is were the user enters the number of the message recipient -->

    <EditText
        android:id="@+id/etRecipient"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/enter_recioient"
        android:inputType="number" />

    <!-- tihs is an instraction lable -->

    <TextView
        android:id="@+id/tvProvider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/provider" />

    <!-- this is a dropdown(spinner) where the user selects the provider -->

    <Spinner
        android:id="@+id/spProvider_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/provider_prompt" />

    <TextView
        android:id="@+id/tvMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/massage" />

    <EditText
        android:id="@+id/etMassage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/type_message" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp"
        android:weightSum="100" >

        <Button
            android:id="@+id/btnSend"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:text="@string/send" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:text="@string/cancel" />
    </LinearLayout>


</LinearLayout> 

广告的java就在这里

LinearLayout lay = (LinearLayout) findViewById(R.id.mainLay);
        AdView adView = new AdView(this, AdSize.SMART_BANNER, pubId);
        lay.addView(adView);
        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        adView.loadAd(adRequest);

这是更新的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/mainLay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".Main" >

    <!-- this is a lable to tell the user to input the recipients number in the input box below -->

    <TextView
        android:id="@+id/tvNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/number" />

    <!-- this is were the user enters the number of the message recipient -->

    <EditText
        android:id="@+id/etRecipient"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/enter_recioient"
        android:inputType="number" />

    <!-- tihs is an instraction lable -->

    <TextView
        android:id="@+id/tvProvider"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/provider" />

    <!-- this is a dropdown(spinner) where the usere selects the provider -->

    <Spinner
        android:id="@+id/spProvider_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/provider_prompt" />

    <TextView
        android:id="@+id/tvMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/massage" />

    <EditText
        android:id="@+id/etMassage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/type_message" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="100" >

        <Button
            android:id="@+id/btnSend"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:text="@string/send" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="50"
            android:text="@string/cancel" />


        <com.google.ads.AdView
            android:id="@+id/ads"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adUnitId = "**************"
            ads:adSize = "BANNER" />
    </LinearLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

使用您想要的任何样式在活动xml中声明您的adView。例如

    <com.google.whatever.AdView
          android:id="@+id/adview"
          <!-- properties list -->
    />

然后在你的代码中你可以这样:

    AdView adView = (AdView) findViewById(R.id.adview);
    AdRequest adRequest = new AdRequest();
    adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
    adView.loadAd(adRequest);