Tag: mobfox

以编程方式设置视图宽度

我正在尝试在代码中设置视图的宽度和高度,以显示我正在处理的免费应用的广告。 除了这个广告,所有的用户界面都以XML格式完成。 以下是显示广告的代码。 它在onCreate 。 AdView adView = new AdView(this,"ad_url","my_ad_key",true,true); LinearLayout layout = (LinearLayout) findViewById(R.id.testing); adView.setAdListener(this); layout.addView(adView); 这导致广告以这种方式显示。 正如你所看到的宽度不完全填满整个页面。 现在当我改变这个代码来尝试设置大小: AdView adView = new AdView(this,"ad_url","my_ad_key",true,true); LinearLayout layout = (LinearLayout) findViewById(R.id.testing); adView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); adView.setAdListener(this); layout.addView(adView); 我得到这个: 我已经尝试了FILL_PARENT和WRAP_CONTENT所有不同组合,结果相同。 有什么我失踪? 或者,我可以让广告填充设备的宽度而不填充高度? 任何build议和帮助,不胜感激。 编辑时,我试图把它放在XML我得到一个exception: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/main_layout"> <fragment android:name="com.jasoncrosby.app.tipcalculatorfree.MainButtonFragment" android:id="@+id/button_frag" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <com.adsdk.sdk.banner.AdView android:id="@+id/banner" android:layout_width="fill_parent" […]