广告移动 |扩大横幅尺寸?

2023-12-25

我的目标是让 admob 横幅位于屏幕底部,如下图所示:http://goo.gl/3POR1n http://goo.gl/3POR1n但我不知道如何做横幅坐在屏幕上,因为我设置了更高的布局填充。

LogCat 说:没有足够的空间来显示广告。需要 320x50 dp,但只有 288x135 dp。

如何扩展我的空间以及如何在底部设置横幅?

我的布局 xml:

<LinearLayout 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"
    android:background="@color/background"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="eu.gabrielatanasov.demoViewer.Home_activity" >

    <ImageView
        android:id="@+id/img_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/img_logo"

    <Button
        android:id="@+id/btn_subscription"
        style="@style/button"
        android:layout_marginTop="1dp"
        android:text="@string/btn_subscription" />

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

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/adMob_ID" >
        </com.google.android.gms.ads.AdView>
    </LinearLayout>

</LinearLayout>

我的dimens.xml:

<resources>
   <!-- Default screen margins, per the Android Design guidelines. -->
   <dimen name="activity_horizontal_margin">16dp</dimen>
   <dimen name="activity_vertical_margin">16dp</dimen>
</resources>

我的活动:

package eu.gabrielatanasov.demoViewer;

import com.google.android.gms.ads.*;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class Home_activity extends Activity {
    Button btn_subscription;

    AdView adView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_home);

        adView = (AdView) this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
        btn_subscription = (Button) findViewById(R.id.btn_subscription);

        btn_subscription.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                vibrateButton(v);
            }
        });
    }

    public void vibrateButton(View v) {
        buttonVibrate = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        buttonVibrate.vibrate(30);
    }
}

包裹你的LinearLayout在另一个里面RelativeLayout。这样,LinearLayout 的填充就不会减少横幅的可用空间。

参见示例:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >   

    <LinearLayout  

    //copy paste your linear layout code here (without AdView).. 

    ...

    </LinearLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/adMob_ID" />

</RelativeLayout>

请注意android:layout_alignParentBottom="true"它将 AdView 与底部对齐

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

广告移动 |扩大横幅尺寸? 的相关文章

随机推荐