Android scrollbar with scroll

is it possible to have a horizontal scrollable tab if there are more than, for example, 10 tabs in it?

Has anyone implemented something like this?

alt text

Moore

Ps. It was not nice what I did: I deleted almost the same topic as yesterday. Great HISTORICAL for a person who has already answered him, even if it was not the answer I am looking for.

+3
source share
1 answer

There is actually a way to implement this, and it is called tabbed layout tables. I managed to use it in one of the applications that I developed and published on Google Play. Here is the code to implement it:

Class SectionPagerAdapter:

public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = new Fragment();
            switch (position) {
            case 0:
                return fragment = new HomeFragment();
            case 1:
                return fragment = new EventFragment();
            case 2:
                return fragment = new CoreTeamFragment();
            case 3:
                return fragment = new MapsFragment();
            case 4:
                return fragment = new FacebookFragment();
            default:
                break;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            // Show 5 total pages.
            return 5;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Locale l = Locale.getDefault();
            switch (position) {
            case 0:
                return getString(R.string.title_section1).toUpperCase(l);
            case 1:
                return getString(R.string.title_section2).toUpperCase(l);
            case 2:
                return getString(R.string.title_section3).toUpperCase(l);
            case 3:
                return getString(R.string.title_section4).toUpperCase(l);
            case 4:
                return getString(R.string.title_section5).toUpperCase(l);
            }
            return null;
        }
    }

Main class

public class CentruActivity extends FragmentActivity {

    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_centru);

        mSectionsPagerAdapter = new SectionsPagerAdapter(
                getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // getActionBar();
    }

    public ActionBar getActionBar() {
        return null;
    }
}

Hope this helps :)

0

Source: https://habr.com/ru/post/1771882/


All Articles