Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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 @+;id/adView“;它是红色的,为什么?_Android - Fatal编程技术网

Android @+;id/adView“;它是红色的,为什么?

Android @+;id/adView“;它是红色的,为什么?,android,Android,为什么是红色的?当我运行应用程序时,adview运行得很好,所以我不知道为什么它不工作。一旦我运行应用程序,红色部分也会消失一段时间。 当我从上面改到下面时,它不会出现错误。@+id/用于创建id。要引用它,请使用@id/。此外,还应将adview的代码置于webview的代码之上,因为需要先定义id,然后才能引用它 试试这个: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:

为什么是红色的?当我运行应用程序时,adview运行得很好,所以我不知道为什么它不工作。一旦我运行应用程序,红色部分也会消失一段时间。
当我从上面改到下面时,它不会出现错误。

@+id/
用于创建id。要引用它,请使用
@id/
。此外,还应将adview的代码置于webview的代码之上,因为需要先定义id,然后才能引用它

试试这个:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
android:background="#ff000640">

<WebView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/webView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"

    android:layout_alignParentTop="true"
    android:layout_above="@+id/adView"
   />

<com.google.android.gms.ads.AdView android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="ca-app-pub"
    ads:adSize="BANNER"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    />

@+id/adView:+符号表示如果新id尚不存在,则生成新id。 我想最好是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
android:background="#ff000640">

    <com.google.android.gms.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ca-app-pub"
        ads:adSize="BANNER"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        />

    <WebView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/webView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"

        android:layout_alignParentTop="true"
        android:layout_above="@id/adView"
       />

</RelativeLayout>

我认为您没有导入Google Admob库。请将此库导入到项目中,然后重试


因为当我尝试你的代码时,任何红线都会出现。只需导入库。

对此不确定,但我认为您应该先添加AdView,然后再添加WebView。除了@Krishnabhadra单词,删除WebView的上述属性中的“+”。此问题似乎与主题无关,因为它对RelativeLa中的相对引用没有最低限度的理解。是否添加了第三个问题party@Anuja对不起,我对这件事知之甚少,你什么意思?是我干的,但是没有区别,你应该从上面的链接一个接一个地完成这些步骤。我使用的是Android Studio,并遵循了所有步骤。我的代码中的一切都很好,但是@id/adView…我只是将您的xml添加到我的xml代码中,没有红线。确保导入和路径正常工作。是否有任何错误消息?如果是这样,它会说什么?红色下划线表示:顶层元素未完成您是否关闭了RelativeLayout(文档末尾带有
-标记),如我的解决方案所示?
<WebView ...
         android:layout_above="@id/adView"