简体   繁体   English

动态将adview(admob)添加到linearlayout

[英]Adding adview(admob) to linearlayout dynamically

I want to display on the top of activity which consist of scrollable tableview. 我想显示在由可滚动表格视图组成的活动的顶部。 The content and number of rows are dynamic in tableview. 表格视图中的内容和行数是动态的。

when I try to run the below code, It shows me table until when the ad is loaded, but when the ad is loaded the tableview disappears. 当我尝试运行以下代码时,它会向我显示表格,直到加载广告为止,但是加载广告后,tableview消失了。 I dont understand why this is happening. 我不明白为什么会这样。

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="***********"
        ads:loadAdOnCreate="true" />

    <ScrollView
        android:id="@+id/scroll1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TableLayout
            android:id="@+id/table_layout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <TableRow>

                <TextView
                    android:id="@+id/left_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:gravity="left|center_vertical"
                    android:padding="5dip"
                    android:text="Code" />

                <TextView
                    android:id="@+id/middle_text"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right|center_vertical"
                    android:padding="5dip"
                    android:text="Name of Company" />

                <TextView
                    android:id="@+id/right_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"
                    android:gravity="right|center_vertical"
                    android:padding="5dip"
                    android:text="1.3" />
            </TableRow>
        </TableLayout>
    </ScrollView>

</LinearLayout>

Yout tablelayout width is fillparent. 您的表格布局宽度为fillparent。 Change it to wrap content. 更改以包装内容。

The default orientation of LinearLayout is horizontal. LinearLayout的默认方向是水平。 When ads is loaded, all contents shifts to the right. 加载广告后,所有内容都会向右移动。 You should set orientation of the LinearLayout to vertical. 您应该将LinearLayout方向设置为垂直。 Add this to your LinearLayout : 将此添加到您的LinearLayout

android:orientation="vertical"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM