Skip to content
Advertisement

What is the best way to have a banner that slides just below my search bar? [closed]

I’ve tried everything, please help.

Advertisement

Answer

Assuming you want something like sliding images, if that is it I think you’re looking for a ViewPager

You can add your content to the ViewPager. For them to automatically keep swiping you can try something like this or this.

This piece of code-block would achieve the same:

viewPager = (ViewPager) findViewById(R.id.viewPager);
    PagerAdapter adapter = new CustomAdapter(MainActivity.this,imageId,imagesName);
    viewPager.setAdapter(adapter);

    /*After setting the adapter use the timer */
    final Handler handler = new Handler();
    final Runnable Update = new Runnable() {
        public void run() {
            if (currentPage == NUM_PAGES-1) {
                currentPage = 0;
            }
            viewPager.setCurrentItem(currentPage++, true);
         }
     };

    timer = new Timer(); // This will create a new Thread 
    timer.schedule(new TimerTask() { // task to be scheduled
        @Override
        public void run() {
            handler.post(Update);
        }
    }, DELAY_MS, PERIOD_MS);

Hope that does what you need!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement