AdMob广告|扩展横幅大小? [英] adMob | Extend Banner size?
问题描述
我的目标是让AdMob的展架在屏幕的底部,在这张照片: http://goo.gl / 3POR1n 但我不知道该怎么办的旗帜坐打,因为更高的布局我设置填充屏幕。
LogCat中说:没有足够的空间来显示广告。需要320x50的DP,但只有288x135 DP。
如何延长我的空间,以及如何在底部设置的旗帜?
我的布局XML:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:广告=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@颜色/背景
机器人:方向=垂直
机器人:paddingBottom会=@扪/ activity_vertical_margin
机器人:以下属性来=@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:paddingTop =@扪/ activity_vertical_margin
工具:上下文=eu.gabrielatanasov.demoViewer.Home_activity>
< ImageView的
机器人:ID =@ + ID / img_logo
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:contentDescription =@字符串/ img_logo
<按钮
机器人:ID =@ + ID / btn_subscription
风格=@风格/按钮
机器人:layout_marginTop =1DP
机器人:文本=@字符串/ btn_subscription/>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
< com.google.android.gms.ads.AdView
机器人:ID =@ + ID / AD浏览报
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
广告:adSize =SMART_BANNER
广告:adUnitId =@字符串/ adMob_ID>
< /com.google.android.gms.ads.AdView>
< / LinearLayout中>
< / LinearLayout中>
我的dimens.xml:
<资源>
<! - 默认屏幕空间,每个Android的设计准则。 - >
<扪名=activity_horizontal_margin> 16DP< /扪>
<扪名=activity_vertical_margin> 16DP< /扪>
< /资源>
我的活动:
包eu.gabrielatanasov.demoViewer;
进口com.google.android.gms.ads *。
进口android.app.Activity;
进口android.content.Context;
进口android.os.Bundle;
进口android.os.Vibrator;
进口android.view.View;
进口android.view.Window;
进口android.widget.Button;
公共类Home_activity延伸活动{
按钮btn_subscription;
AD浏览报AD浏览报;
@覆盖
保护无效的onCreate(包savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
overridePendingTransition(R.anim.slide_in,R.anim.slide_out);
super.onCreate(savedInstanceState);
的setContentView(R.layout.layout_home);
AD浏览报=(AD浏览报)this.findViewById(R.id.adView);
AdRequest adRequest =新AdRequest.Builder()建立()。
adView.loadAd(adRequest);
btn_subscription =(按钮)findViewById(R.id.btn_subscription);
btn_subscription.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
vibrateButton(五);
}
});
}
公共无效vibrateButton(视图v){
buttonVibrate =(震动)getSystemService(Context.VIBRATOR_SERVICE);
buttonVibrate.vibrate(30);
}
}
包装你的的LinearLayout
另一个 RelativeLayout的
里面。这样的LinearLayout中的填充不会减少横幅的可用空间。
请参阅例如:
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:广告=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / mainLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的LinearLayout
//这里复制粘贴您的线性布局code(不带AD浏览报)..
...
< / LinearLayout中>
< com.google.android.gms.ads.AdView
机器人:ID =@ + ID / AD浏览报
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:layout_alignParentBottom =真
广告:adSize =SMART_BANNER
广告:adUnitId =@字符串/ adMob_ID/>
< / RelativeLayout的>
注意安卓layout_alignParentBottom =真正的
这对准AD浏览报至底部
My goal is to make admob banner stand at the bottom of the screen as in this photo: http://goo.gl/3POR1n But I do not know how to do banner sits hit the screen because of the higher layout i set padding.
LogCat say: Not enough space to show ad. Needs 320x50 dp, but only has 288x135 dp.
How to extend my space and how to set banner at bottom ?
My layout 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>
My 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>
My activity:
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);
}
}
Wrap your LinearLayout
inside another RelativeLayout
. That way the LinearLayout's padding won't reduce the available space for the banner.
See example:
<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>
Note the android:layout_alignParentBottom="true"
which aligns the AdView to the bottom
这篇关于AdMob广告|扩展横幅大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!