改变AdMob的横幅尺寸动态 [英] changing admob banner size dynamically
问题描述
下面的事情,因为你可能知道Admob的有一个 AdSize。*
函数,其中u把横幅
显示横幅广告,并AD_banner`平板横幅,我想要做的就是采取了设备的屏幕大小,这样我可以把它我的if语句,然后把正确的横幅正确的设备,我希望我是清楚的enough.So任何人都可以告诉我,我怎么能得到设备的屏幕尺寸是多少?
感谢你
//////////
这是我迄今所做的
DisplayMetrics DM =新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(DM)。
如果(dm.density == DisplayMetrics.DENSITY_HIGH){
AD浏览报AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,S);
的LinearLayout布局=(的LinearLayout)findViewById(R.id.admob);
layout.addView(AD浏览报);
adView.loadAd(新AdRequest());
}
如果(dm.density == DisplayMetrics.DENSITY_DEFAULT || dm.density == DisplayMetrics.DENSITY_LOW){
AD浏览报AD浏览报=新的AD浏览报(这一点,AdSize.BANNER,S);
的LinearLayout布局=(的LinearLayout)findViewById(R.id.admob);
layout.addView(AD浏览报);
adView.loadAd(新AdRequest());
}
如果(dm.density == DisplayMetrics.DENSITY_MEDIUM)
{
AD浏览报AD浏览报=新的AD浏览报(这一点,AdSize.IAB_BANNER,S);
的LinearLayout布局=(的LinearLayout)findViewById(R.id.admob);
layout.addView(AD浏览报);
adView.loadAd(新AdRequest());
}
如果您的布局定义一个XML,可以为每个屏幕尺寸(布局XLARGE / mylayout.xml,布局大/ mylayout.xml一种布局,布局正常/ mylayout.xml,等...)
这里更多信息:<一href="http://developer.android.com/guide/practices/screens_support.html">http://developer.android.com/guide/practices/screens_support.html
别看密度,因为,一个10.1平板电脑具有中等密度,而是一个4.3的手机具有480x850的分辨率将有一个高密度。使用屏幕大小,而不是(XLARGE大中小)。
如果您需要以编程方式做到这一点,你可以在屏幕尺寸是:
配置配置= activity.getResources()getConfiguration()。
INT屏幕布置= config.screenLayout;
和比较,使用Configuration.SCREENLAYOUT_xxx。
Here is the thing, as you might know Admob has a AdSize.*
function, where u put Banner
to show banner ads, and AD_banner` for tablet banners, what i want to do is take a screen size of a device so that i could throw it in my if statement and then put the right banner for right device, i hope i was clear enough.So anyone can tell me how can i get the screen size of device?
Thank u
//////////
Here's what i have done so far
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
if (dm.density==DisplayMetrics.DENSITY_HIGH) {
AdView adView = new AdView(this, AdSize.BANNER,s);
LinearLayout layout = (LinearLayout)findViewById(R.id.admob);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
if (dm.density==DisplayMetrics.DENSITY_DEFAULT || dm.density==DisplayMetrics.DENSITY_LOW ) {
AdView adView = new AdView(this, AdSize.BANNER,s);
LinearLayout layout = (LinearLayout)findViewById(R.id.admob);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
if(dm.density==DisplayMetrics.DENSITY_MEDIUM)
{
AdView adView = new AdView(this, AdSize.IAB_BANNER,s);
LinearLayout layout = (LinearLayout)findViewById(R.id.admob);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
If your layout is define in a xml, you can create one layout per screen size (layout-xlarge/mylayout.xml, layout-large/mylayout.xml, layout-normal/mylayout.xml, etc...)
More info here : http://developer.android.com/guide/practices/screens_support.html
Don't look at density, because, a 10.1" tablet has a medium density, but a 4.3" phone with a 480x850 resolution will have a high density. Use screen size instead (xlarge large normal small).
If you need to do it programatically, you can get the screen size with this :
Configuration config = activity.getResources().getConfiguration();
int screenlayout = config.screenLayout;
and to compare, use Configuration.SCREENLAYOUT_xxx .
这篇关于改变AdMob的横幅尺寸动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!