adMob |延长横幅尺寸?

时间:2014-09-28 18:54:37

标签: android android-layout layout size admob

我的目标是让adob横幅站在屏幕的底部,就像在这张照片中一样:http://goo.gl/3POR1n但我不知道怎么做横幅坐在屏幕上,因为我设置了更高的布局填充。< / p>

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

1 个答案:

答案 0 :(得分:1)

将您的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>

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