我正在我的应用程序中插入 AdMob。但我有一个问题。
当我在 Eclipse 中插入一些相关代码时,我可以在fragment_03中看到一条关于“构造函数 AdRequest() 不可见”的错误消息,以及“错误:解析 XML 时出错:未绑定前缀”
所以我附上了 AdMob 的源代码,如下所示。
你能给我一个建议吗?
如果您有任何疑问,请告诉我。
Thanks
-
片段_03.java
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class Fragment_03 extends Fragment {
private AdView adView;
private AdRequest adRequest;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_03, container, false);
adRequest = new AdRequest();
adView = (AdView) rootView.findViewById(R.id.fragment_03_admob);
adView.loadAd(adRequest);
return rootView;
}
}
-
片段_03.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.ads.AdView
xmlns:ads="schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/fragment_03_admob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/activity_admobID"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>
-
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
按以下方式更改布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.ads.AdView
android:id="@+id/fragment_03_admob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/activity_admobID"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>
您使用了错误的名称空间声明。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)