【问题标题】:Integrate Admob adview into TableLayout / TableRow将 Admob adview 集成到 TableLayout / TableRow
【发布时间】:2016-11-16 03:28:05
【问题描述】:

我正在尝试将 Admob 集成到我的 TableLayout 中。不幸的是,它从未在屏幕上显示。布局仅包含顶部的一些文本字段和一个地图视图,广告视图应放置在底部。我的 XML 布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" 
android:id="@+id/main">

<TableRow>

    <TextView
        android:id="@+id/txt1"
        android:gravity="center"
        android:text="text1"
        android:textSize="25sp" 
        android:layout_span="3"/>
</TableRow>


<TableRow>
    <TextView
    android:id="@+id/txt2"
    android:gravity="center"
    android:text="txt2"
    android:textSize="25sp"
    android:layout_span="3"
    />

</TableRow>

<TableRow>

    <TextView
        android:id="@+id/txt3"
        android:gravity="left"
        android:text="txt3"
        android:textSize="25sp" 
        android:paddingLeft="20sp"/>

    <TextView
        android:id="@+id/txt4"            
        android:gravity="right"
        android:text="txt4"
        android:textSize="25sp"
        android:paddingRight="20sp"/>
</TableRow>

<TableRow>
<com.google.android.maps.MapView
    android:layout_span="2"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:apiKey="XXX"
    android:clickable="true"
    />
 </TableRow>

<TableRow>

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="XXX"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, XXX"
                     ads:loadAdOnCreate="true"
                     android:layout_span="2"
                     />  
</TableRow>
</TableLayout>

谁能告诉我为了正确显示 Adview 我必须进行哪些更改?

【问题讨论】:

  • 将您的广告视图封装在某个布局中?可能是相对布局并尝试。这是其他 SO 讨论的参考链接(我知道这个链接是针对 TabHost 而不是 TableLayout,但概念是相同的)stackoverflow.com/questions/3576117/…
  • 我已经这样尝试过了,但这也没有用:(
  • 您是否在 logcat 中看到显示已收到广告提要的日志?如果是这样,主要是你的布局设置,玩高和宽度等,
  • 是的,因为我处于测试模式。似乎问题确实是xml。此外,如果我将 mapview 的高度更改为 100px,则会显示 Adview。但如果我设置 height = wrap_content.

标签: android admob android-tablelayout


【解决方案1】:

试试这种方式,因为我创建了简单的演示供您理解...!?! 我觉得对你有帮助

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:shrinkColumns="*"
android:stretchColumns="*" >

<TableRow
    android:id="@+id/tableRow0"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0"
    android:background="@drawable/info_headstriplogo"
    android:gravity="top" >

    <ImageButton
        android:id="@+id/ibGMapLocationBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|bottom"
        android:layout_margin="5dp"
        android:layout_span="2"
        android:background="@null"
        android:contentDescription="@id/ibGMapLocationBack"
        android:src="@drawable/back" />
</TableRow>

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <com.google.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_span="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:apiKey="0zzbEqGyRIg8wikQPkcwDvqhM6x0TwcSHozLlZg"
        android:clickable="true"
        android:enabled="true" />
</TableRow>

<TableRow
    android:id="@+id/tableRow10"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:background="@drawable/footerstrip"
    android:gravity="bottom" >
</TableRow>

【讨论】:

    猜你喜欢
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    相关资源
    最近更新 更多