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