0
我有一个可以正常工作的xml布局,但我尝试过插入AdView的AdMob广告,但它不再工作。在日志中,我只能看到“before”文本,但我看不到“after”文本。这可能是由于什么原因造成的?为什么充气机不能充气?
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
//Stuff...
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
//Stuff...
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
//Stuff...
</TableRow>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-0771856019955508/3441120220"
ads:adSize="BANNER" />
</TableLayout>
HomeFragment.java
public class HomeFragment extends Fragment {
private View rootView;
private AdView adview1;
private AdRequest adRequest;
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.e("Et_ad","before");
rootView = inflater.inflate(R.layout.fragment_home, container, false);
Log.e("Et_ad","after");
//Stuff...
adview1 = (AdView)rootView.findViewById(R.id.adView1);
Log.e("Et_ad","adview1");
adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
Log.e("Et_ad","before load adview1");
adview1.loadAd(adRequest);
return rootView;
}
也许是因为您的AdView不在TableRow内?如果日志中有任何异常? – William
所以也许我应该尝试一个带有TableLayout和adView的LinearLayout?我稍后再尝试一下,并说一些关于它的信息 – user1903
好的,我已经改变了这一点,以防万一;我很确定'adview1.loadAd(adRequest);'是什么让我的应用程序崩溃;任何帮助? – user1903