Questions tagged «mobfox»

7
以编程方式设置视图宽度
我正在尝试在代码中设置视图的宽度和高度,以显示我正在开发的免费应用的广告。除此广告外,所有用户界面均以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都得到了相同的结果。我有什么想念的吗?还是可以通过其他方式让广告填充设备的宽度而不填充高度?任何建议和帮助,我们将不胜感激。 当我尝试将其放入XML时进行编辑时出现异常: <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" android:layout_height="wrap_content"/> </LinearLayout> > …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.