AdMob Android 帮助
我在将 admob 正确放入布局时遇到问题。不管我怎么说,我似乎根本看不到广告。这是 2 个布局...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>
layout2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dip"
android:background="#0000">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#0000">
<TableRow>
<TextView
android:id="@+id/description"
android:padding="2dip"
android:textColor="#ffff"
android:background="#0000"/>
</TableRow>
</TableLayout>
</LinearLayout>
和 admob java 的代码是 android:id="@+id/线性布局" 已经在主布局中。问题是它不显示,但如果我创建一个新项目,除了带有在线布局的 admob java 部分之外什么都没有,我可以看到广告。
是的,我在主体中添加了正确的代码
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
,我也被告知要使用相对布局,但这也不起作用,除非我做错了。希望有人可以帮忙!
更新1: 这是 @+id/linearLayout 到 admob 使用的 java 代码
// Lookup R.layout.main
LinearLayout layout =
(LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, "a14e458091154df");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
i am having problems putting admob in the layout correctly. no matter how i put it i cant seem to see the ads at all. here are the 2 layouts...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>
layout2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="10dip"
android:background="#0000">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#0000">
<TableRow>
<TextView
android:id="@+id/description"
android:padding="2dip"
android:textColor="#ffff"
android:background="#0000"/>
</TableRow>
</TableLayout>
</LinearLayout>
and the code to the admob java is
android:id="@+id/linearLayout"
already in the main layout. the problem is that it doesnt display but if i make a new project with nothing but the admob java part with the layout online i can see the ads.
and yes i have added the proper codes in the main
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
also i was told to use relative layout but that also doesnt work unless i am doing it wrong. hope someone can help!
UPDATE1:
here is the java code used by @+id/linearLayout to admob
// Lookup R.layout.main
LinearLayout layout =
(LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.BANNER, "a14e458091154df");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的 main.xml 中添加一个 AdView,如下例所示,也不要忘记添加
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
到主 LinearLayout 定义,并将 MY_AD_UNIT_ID 替换为您的 adMob 发布商 ID
另请参阅 此页面。
In your main.xml add an AdView as per the example below, also don't forget to add the
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
to the main LinearLayout definition, and replace MY_AD_UNIT_ID with your adMob publisher ID
Also see more examples on this page.