AdMob Android 帮助

发布于 2024-11-29 14:11:19 字数 2363 浏览 0 评论 0原文

我在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

败给现实 2024-12-06 14:11:19

在您的 main.xml 中添加一个 AdView,如下例所示,也不要忘记添加
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
到主 LinearLayout 定义,并将 MY_AD_UNIT_ID 替换为您的 adMob 发布商 ID

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:loadAdOnCreate="true"/>
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>

另请参阅 此页面

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000">
  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:loadAdOnCreate="true"/>
<ListView
android:id="@+id/android:list"
android:background="#0000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="1dip"/>
</LinearLayout>

Also see more examples on this page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文