2016-05-22 23 views
1

こんにちは私は多くのトピックを読んで、私は何が間違っているのか分かりません。私は必須のXML属性adSizeがありませんでした

ads:adSize="BANNER" 
    ads:adUnitId="@string/admob" 

その作業罰金含むが、私が欲しいプログラムでAdMobのコードが含まれている場合

Start.java

public class Start extends _fragment { 
    public Start() { super(); this.context = M.context; } 

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.site_reklama, container,false); 

     AdView adView = (AdView) view.findViewById(R.id.adView); 
     adView.setAdUnitId(M.admob); 
     adView.setAdSize(AdSize.BANNER); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     adView.loadAd(adRequest); 

     return view; 
    } 
} 

site_reklama.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
      xmlns:ads="http://schemas.android.com/apk/res-auto" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

<include layout="@layout/site_start"/> 

<com.google.android.gms.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentTop="true"> 
</com.google.android.gms.ads.AdView>  

</RelativeLayout> 

答えて

0

回答:

public class Start extends _fragment { 

    public Start() { super(); this.context = M.context; } 

    private static AdView adView; 

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 

      View view = inflater.inflate(R.layout.site_reklama, container,false); 
      adView = new AdView(getActivity()); 
      adView.setAdUnitId(M.admob); 
      adView.setAdSize(AdSize.BANNER); 
      RelativeLayout layout = (RelativeLayout)view.findViewById(R.id.rr); 
      layout.addView(adView); 
      AdRequest adRequest = new AdRequest.Builder().build(); 
      adView.loadAd(adRequest); 

     return view; 
    } 

} 

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/rr" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

<include layout="@layout/site_start"/> 

</RelativeLayout> 
関連する問題