Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Admob AdBanner加载导致碎片变形_Android_Android Fragments_Admob - Fatal编程技术网

Android Admob AdBanner加载导致碎片变形

Android Admob AdBanner加载导致碎片变形,android,android-fragments,admob,Android,Android Fragments,Admob,在我的应用程序中,主屏幕上有4个按钮,每个按钮都会打开一个新的活动。每个活动都包含一个片段,在片段的末尾有Admob横幅。每个片段的基本布局如下所示: 每个活动上的横幅加载良好,但如果我一次又一次地从一个活动切换到另一个活动,我会看到随机中断的视图s的扭曲显示。当我单击任意位置时,它会得到修复 横幅的问题只是因为当我关掉互联网时一切都很好 有什么建议吗 表2.1-1布局图: <RelativeLayout xmlns:android="http://schemas.android.com

在我的应用程序中,主屏幕上有4个
按钮
,每个按钮都会打开一个新的
活动
。每个
活动
都包含一个
片段
,在
片段
的末尾有
Admob
横幅。每个
片段的基本布局如下所示:

每个
活动
上的横幅加载良好,但如果我一次又一次地从一个
活动
切换到另一个
活动,我会看到随机中断的
视图
s的扭曲显示。当我单击任意位置时,它会得到修复

横幅的问题只是因为当我关掉互联网时一切都很好

有什么建议吗

表2.1-1布局图:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"   android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.apps.toffeesoft.easyqrReader.HomeScreenActivityFragment">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/adViewHome"
    android:layout_height="wrap_content">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/home_background"

    >
    <TableRow

        >
        <Button
            android:id="@+id/btnScan"
            android:elevation="@dimen/abc_control_corner_material"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginBottom="-6dp"
            android:layout_marginRight="-7dp"

            android:layout_height="wrap_content"
            android:text="@string/home_scan_heading"
            android:drawableTop="@drawable/ic_image_camera_alt" />

        <Button
            android:id="@+id/btnCreate"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginBottom="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/home_create_plain_heading"
            android:drawableTop="@drawable/create_qr_plain"
            />
    </TableRow>
    <TableRow
        android:layout_width="match_parent">
        <Button
            android:id="@+id/btnCreateContact"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginRight="-7dp"
            android:layout_marginTop="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/home_create_contact_qr_heading"
            android:drawableTop="@drawable/contact_image"
            />
        <Button
            android:id="@+id/btnQrHistory"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginTop="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/qr_history"
            android:drawableTop="@drawable/history"
            />


    </TableRow>
</TableLayout>
</LinearLayout>
<!--
<com.google.android.gms.ads.AdView
    android:id="@+id/adViewHome"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ad_bottom_home_screen_banner">
</com.google.android.gms.ads.AdView>
-->
</RelativeLayout>

您的
片段的第一个总体布局与其
视图
无关。您的
视图组
线性布局
包含一些东西
高度
匹配父项
,看看这个,假设这会填满整个屏幕,但是你有一个
Admob
视图
,它位于父视图组的底部
,这也是
匹配父视图
,因此你的
视图将没有定位

相反,将
线性布局
设置为滚动视图,如果
视图
s足以填满屏幕,或者干脆让
线性布局
位于
Admob

<LinearLayout
   android:layout_width="match_parent"
   android:orientation="vertical"
   android:layout_above="@+id/theidoftheadmob"
   android:layout_height="match_parent">
   //some stuff here
</LinearLayout>

//这里有些东西

Elltz,谢谢你的建议。我尝试了你的两个建议,但结果相同:(.我甚至尝试在活动版面中放置广告横幅,而不是片段版面,但同样的结果。我还将版面高度更改为包裹父级,但没有效果。你能发布一张它是如何完成的图片吗looks@Vikram我会投票给你,这样你就有足够的代表了。我仍然无法添加图片。我已经在这个链接上传了。请稍等,你有
Adv吗查看
活动中的
布局和片段布局?从您的帖子中,我将其视为xml
adViewEncodeManual
中admob的id,并在
片段
类中查看
onActivityCreate()
方法,我看到
(AdView)getActivity()。findViewById(R.id.adViewHome)
这意味着您正在将外接程序加载到活动布局中的不同布局中。而不是片段布局。您明白我的意思吗?如果您仍然不让我发布您的活动布局xml@VikramEarlier我把横幅放在碎片里,然后我把它移到了活动中。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"   android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.apps.toffeesoft.easyqrReader.HomeScreenActivityFragment">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/adViewHome"
    android:layout_height="wrap_content">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/home_background"

    >
    <TableRow

        >
        <Button
            android:id="@+id/btnScan"
            android:elevation="@dimen/abc_control_corner_material"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginBottom="-6dp"
            android:layout_marginRight="-7dp"

            android:layout_height="wrap_content"
            android:text="@string/home_scan_heading"
            android:drawableTop="@drawable/ic_image_camera_alt" />

        <Button
            android:id="@+id/btnCreate"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginBottom="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/home_create_plain_heading"
            android:drawableTop="@drawable/create_qr_plain"
            />
    </TableRow>
    <TableRow
        android:layout_width="match_parent">
        <Button
            android:id="@+id/btnCreateContact"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginRight="-7dp"
            android:layout_marginTop="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/home_create_contact_qr_heading"
            android:drawableTop="@drawable/contact_image"
            />
        <Button
            android:id="@+id/btnQrHistory"
            android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_marginTop="-6dp"
            android:layout_height="wrap_content"
            android:text="@string/qr_history"
            android:drawableTop="@drawable/history"
            />


    </TableRow>
</TableLayout>
</LinearLayout>
<!--
<com.google.android.gms.ads.AdView
    android:id="@+id/adViewHome"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="BANNER"
    ads:adUnitId="@string/ad_bottom_home_screen_banner">
</com.google.android.gms.ads.AdView>
-->
</RelativeLayout>
<LinearLayout
   android:layout_width="match_parent"
   android:orientation="vertical"
   android:layout_above="@+id/theidoftheadmob"
   android:layout_height="match_parent">
   //some stuff here
</LinearLayout>