Native Ad Scroll View

Creates a native ad horizontal scroll view for a given native ads manager and native ad template. The manager can be preloaded with ads, and loadAds will use the preloaded ads from the manager. Otherwise, the scroll view uses the manager to load ads normally.

Implementation

Before you start, if you haven't done so yet, follow the steps in our getting started guide to set up the SDK.

Initialize the Audience Network SDK and load ads via the native ads manager:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hscroll);

        manager = new NativeAdsManager(this, "YOUR_PLACEMENT_ID", 5);
        manager.setListener(this);
        manager.loadAds(NativeAd.MediaCacheFlag.ALL);

     @Override
     public void onClick(View v) {
        manager.loadAds();
            }
        });

Render NativeAdScrollView by providing a loaded NativeAdsManager and a native ad template or publisher defined UI View via the native ads api:

    @Override
    public void onAdsLoaded() {
        Toast.makeText(this, "Ads loaded", Toast.LENGTH_SHORT).show();

        if (scrollView != null) {
            ((LinearLayout) findViewById(R.id.hscrollContainer)).removeView(scrollView);
        }

        scrollView = new NativeAdScrollView(NativeAdHscrollActivity.this, manager,
                NativeAdView.Type.HEIGHT_400);

        ((LinearLayout) findViewById(R.id.hscrollContainer)).addView(scrollView);
    }

The native horizontal scroll view is preloaded with 5 ads. However, you can load the scroll view with more ads by defining a max ad parameter to the scroll view constructor.