问题描述
我在我的应用程序中插入了一个 AdMob.但我有一个问题.
I'm inserting an AdMob in my application. but I have a problem about it.
当我在 Eclipse 中插入一些关于它的代码时,我可以在 fragment_03 中看到一条关于构造函数 AdRequest() 不可见"的错误消息,以及错误:解析 XML 时出错:未绑定前缀"来自
所以我附上了 AdMob 的源代码,如下所示.
when I inserted some codes about it in Eclipse, I can see an error message about "the constructor AdRequest() is not visible " in a fragment_03 and "error: Error parsing XML : unbound prefix" from "
so I attached source for the AdMob as follows.
你能给我一个建议吗?
如果您有任何问题,请告诉我.
Let me know if you have any question.
谢谢
fragment_03.java
fragment_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;
}
}
fragment_03.xml
fragment_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
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>
您使用了错误的命名空间声明.
You was using a wrong namespace declaration.
这篇关于片段中的 AdMob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!