2017-08-06 115 views
0

我有自定義視圖活動,我想在其中顯示廣告。只是在屏幕底部的橫幅視圖。我正在使用Appodeal的廣告API。 這裏是我試過到目前爲止:在自定義視圖中顯示廣告橫幅

public class main extends AppCompatActivity { 

    BannerView bannerView; 
    View customView; 

    public static void loadAd(Context context, Activity activity) { 
      Appodeal.setTesting(true); 
      Appodeal.disableNetwork(context, "cheetah"); 
      Appodeal.disableLocationPermissionCheck(); 
      Appodeal.setBannerViewId(R.id.appodealBannerView); 
      Appodeal.initialize(activity, context.getString(R.string.app_key), Appodeal.BANNER_VIEW); 
      Appodeal.show(activity, Appodeal.BANNER_VIEW); 
     } 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     customView = new CustomView(this, null); 
     setContentView(customView); 

     bannerView = new BannerView(this, null); 
     bannerView.setId(R.id.appodealBannerView); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 

     loadAd(this, this); 
    } 

    class CustomView extends View { 
     CustomView(Context ctx, AttributeSet attrs) { 
      super(ctx, attrs); 
     } 

     @Override 
     protected void onDraw(Canvas canvas) { 
      super.onDraw(canvas); 

      bannerView.draw(canvas); 

      invalidate(); 
     } 
    } 
} 

任何幫助將不勝感激!

回答

1

U可以使用XML佈局如下,例如:

<RelativeLayout 
...> 
<PathToCustomView.CustomView 
    ... 
    /> 

<PathToBannerView.BannerView 
    android:below="+id/myCustomviewId" 
    ... 
    /> 

</RelativeLayout>