【问题标题】:how to declare elements inside layout.xml如何在 layout.xml 中声明元素
【发布时间】:2014-07-22 15:56:34
【问题描述】:

我今天刚刚开始玩 android/sdk 很抱歉这个非常愚蠢的问题,但我正在学习。

我正在使用 Eclipse,我已将一些代码放入项目的 java 文件中,以便将应用程序连接到广告服务器,它工作正常,当我启动应用程序时,我得到了我的广告横幅。 我已经导入了 android sdk 和广告服务提供商 sdk。

现在,我想在布局 xml 中创建的一些对象之间插入横幅。

所以,我在布局文件夹下有 fragment_main.xml,我在其中放置了以下 xml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:opensdk="http://schemas.android.com/apk/res/com.example.myfirstapp"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" >

    <Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/button_send"
       android:onClick="sendMessage" />


    <com.appnexus.opensdk.BannerAdView
       android:id="@+id/banner"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:placement_id="YOUR PLACEMENT ID"
       android:auto_refresh="true"
       android:auto_refresh_interval="30"
       android:opens_native_browser="true"
       android:adWidth="320"
       android:adHeight="50"
       android:should_reload_on_resume="true"
       android:opens_native_browser="true"
       android:expands_to_fit_screen_width="false"
       />

现在对应

    <com.appnexus.opensdk.BannerAdView 

我收到此错误:

Multiple annotations found at this line:
    - error: No resource identifier found for attribute 'auto_refresh_interval' in package 'android'
    - error: No resource identifier found for attribute 'adHeight' in package 'android'
    - error: No resource identifier found for attribute 'expands_to_fit_screen_width' in package 
     'android'
    - error: No resource identifier found for attribute 'should_reload_on_resume' in package 
     'android'
    - error: No resource identifier found for attribute 'placement_id' in package 'android'
    - error: No resource identifier found for attribute 'adWidth' in package 'android'
    - error: No resource identifier found for attribute 'opens_native_browser' in package 'android'
    - error: No resource identifier found for attribute 'auto_refresh' in package 'android'

那么,我在哪里声明所有这些属性?它一定与这条路径有关: xmlns:opensdk="http://schemas.android.com/apk/res/com.example.myfirstapp"

如果您能提供帮助,请告诉我,对于糟糕的信息,我们深表歉意!

【问题讨论】:

    标签: android xml eclipse sdk


    【解决方案1】:

    改变这个

    <com.appnexus.opensdk.BannerAdView
           android:id="@+id/banner"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:placement_id="YOUR PLACEMENT ID"
           android:auto_refresh="true"
           android:auto_refresh_interval="30"
           android:opens_native_browser="true"
           android:adWidth="320"
           android:adHeight="50"
           android:should_reload_on_resume="true"
    
           android:expands_to_fit_screen_width="false"
           />
    

      <com.appnexus.opensdk.BannerAdView
               android:id="@+id/banner"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               opensdk:placement_id="YOUR PLACEMENT ID"
               opensdk:auto_refresh="true"
               opensdk:auto_refresh_interval="30"
               opensdk:opens_native_browser="true"
               opensdk:adWidth="320"
               opensdk:adHeight="50"
               opensdk:should_reload_on_resume="true"
    
               opensdk:expands_to_fit_screen_width="false"
               />
    

    因为您正在为横幅视图使用自定义命名空间

    xmlns:opensdk="http://schemas.android.com/apk/res/com.example.myfirstapp"
    

    【讨论】:

    • @Simone 如果解决了,请采纳,这样也可以帮助到其他人
    【解决方案2】:

    如你所见here - 为了使用 appnexus,你应该这样做:

    第 1 步。下载代码。

    如果你有 gitbash,你可以使用这个命令从 github 下载它git clone git@github.com:appnexus/mobile-sdk-android.git

    您也可以使用浏览器前往https://github.com/appnexus/mobile-sdk-android 并以 .zip 文件下载。

    步骤 2. 将 appnexus SDK 作为库导入

    使用 Android IDE 将 sdk 目录作为库导入您的工作区。

    第 3 步。添加活动

    您必须将以下活动添加到您的 清单 中,SDK 才能正常工作:

    <application
      <activity android:name="com.appnexus.opensdk.AdActivity" />
    </application>
    

    第 4 步。编辑应用权限

    编辑您的 Android ma​​nifest 以包含此应用所需的权限:

    <!-- Add the permissions here... -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

    你可能知道:

    ACCESS_NETWORK_STATE(必需)- 授予 SDK 检查实时互联网连接的权限。

    INTERNET(必需)- 授予 SDK 访问 Internet 的权限。

    ACCESS_COARSE_LOCATION(推荐)- 授予 SDK 访问基于手机信号塔的大概位置的权限。

    ACCESS_FINE_LOCATION(推荐)- 授予 SDK 访问基于 GPS 的更准确位置的权限。

    祝你一切顺利!

    【讨论】:

      猜你喜欢
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多