在布局底部设置adMob广告

时间:2013-12-24 01:35:05

标签: android layout admob

我似乎无法将我的广告显示在最底层。它出现在我的xml布局中的最后一个按钮之后。我尝试了从新布局到重量的一切,它对我不起作用。如果你能提供帮助,那就太好了!

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
            android:id="@+id/reason_1"
            android:layout_width="fill_parent"
            android:layout_height="75dp"
            android:background="@drawable/button"
            android:text="@string/reason_1" />

        <Button
            android:id="@+id/reason_2"
            android:layout_width="fill_parent"
            android:layout_height="75dp"
            android:background="@drawable/button"
            android:text="@string/reason_2" />

        <Button
            android:id="@+id/reason_3"
            android:layout_width="fill_parent"
            android:layout_height="75dp"
            android:background="@drawable/button"
            android:text="@string/reason_3" />

        <Button
            android:id="@+id/reason_button"
            android:layout_width="fill_parent"
            android:layout_height="75dp"
            android:background="@drawable/button_layout"
            android:drawableLeft="@drawable/ic_credit_cards"
            android:drawableRight="@drawable/ic_credit_cards"
            android:text="@string/reason_button_string" />

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            ads:adSize="BANNER"
            ads:adUnitId="xxxxxx"
            ads:loadAdOnCreate="true" >
        </com.google.ads.AdView>
    </LinearLayout>

</ScrollView>

2 个答案:

答案 0 :(得分:1)

我们的想法是使用RelativeLayout并将广告放在底部。然后将Scrollview放在它上面,这样广告就始终位于屏幕的底部。不要使用fill_parent,不推荐使用。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="5dp"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxx"
    ads:loadAdOnCreate="true" >
</com.google.ads.AdView>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/adView" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
        android:id="@+id/reason_1"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_1" />

    <Button
        android:id="@+id/reason_2"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_2" />

    <Button
        android:id="@+id/reason_3"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_3" />

    <Button
        android:id="@+id/reason_button"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button_layout"
        android:drawableLeft="@drawable/ic_credit_cards"
        android:drawableRight="@drawable/ic_credit_cards"
        android:text="@string/reason_button_string" />
    </LinearLayout>
</ScrollView>

</RelativeLayout>

答案 1 :(得分:0)

@svenoaks解决了我的答案3/4的方式。只需要微调它。这是恢复原状。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<com.google.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="5dp"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxx"
    ads:loadAdOnCreate="true" >
</com.google.ads.AdView>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Button
        android:id="@+id/reason_1"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_1" />

    <Button
        android:id="@+id/reason_2"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_2" />

    <Button
        android:id="@+id/reason_3"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button"
        android:text="@string/reason_3" />

    <Button
        android:id="@+id/reason_button"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@drawable/button_layout"
        android:drawableLeft="@drawable/ic_credit_cards"
        android:drawableRight="@drawable/ic_credit_cards"
        android:text="@string/reason_button_text" />
    </LinearLayout>

</RelativeLayout>