为什么充气机没有膨胀视野?

时间:2014-07-11 18:46:35

标签: android android-fragments admob android-inflate

我有一个xml布局工作正常,但我尝试插入AdView的AdMob广告,它不再工作了。在日志中我可以看到"之前"文字,但我看不到""""文本。这可能是什么原因?

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;
    }

1 个答案:

答案 0 :(得分:0)

问题是我粘贴了以下几行:

<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />

<application> ... </application>之外

所以,它应该是:

<application>
    ...
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
    ...
</application>