Java Code Examples for android.support.design.widget.TabLayout#setTabGravity()

The following examples show how to use android.support.design.widget.TabLayout#setTabGravity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalMusicActivity.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void init(){
    addTapData();
    viewPager = (MyViewPager)findViewById(R.id.local_viewPager);
    tabLayout = (TabLayout)findViewById(R.id.local_tab);
    fragmentAdapter = new MyAdapter(getSupportFragmentManager());
    viewPager.setAdapter(fragmentAdapter);
    viewPager.setOffscreenPageLimit(2); //预加载页面数
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(viewPager);

    nothingTv = (TextView)findViewById(R.id.local_nothing_tv);
    nothingTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(LocalMusicActivity.this,ScanActivity.class);
            startActivity(intent);
        }
    });

}
 
Example 2
Source File: LocalMusicActivity.java    From MeetMusic with Apache License 2.0 6 votes vote down vote up
private void init(){
    addTapData();
    viewPager = (MyViewPager)findViewById(R.id.local_viewPager);
    tabLayout = (TabLayout)findViewById(R.id.local_tab);
    fragmentAdapter = new MyAdapter(getSupportFragmentManager());
    viewPager.setAdapter(fragmentAdapter);
    viewPager.setOffscreenPageLimit(2); //预加载页面数
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(viewPager);

    nothingTv = (TextView)findViewById(R.id.local_nothing_tv);
    nothingTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(LocalMusicActivity.this,ScanActivity.class);
            startActivity(intent);
        }
    });

}
 
Example 3
Source File: ViewUtil.java    From MeiZiNews with MIT License 6 votes vote down vote up
/**
 * 动态修改tab的模式
 *
 * @param tabLayout
 */
public static void dynamicSetTablayoutMode(TabLayout tabLayout) {
    int tabTotalWidth = 0;
    for (int i = 0; i < tabLayout.getChildCount(); i++) {
        final View view = tabLayout.getChildAt(i);
        view.measure(0, 0);
        tabTotalWidth += view.getMeasuredWidth();
    }
    if (tabTotalWidth <= MeasureUtil.getScreenSize(tabLayout.getContext()).x) {
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    } else {
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
 
Example 4
Source File: LoginRegisterActivity.java    From BehaviorCollect with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_register);
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    viewPager = (ViewPager) findViewById(R.id.viewPager);

    LoginFragmentPagerAdapter adapter = new LoginFragmentPagerAdapter(getSupportFragmentManager(),
            this);
    viewPager.setAdapter(adapter);

    tabLayout.setupWithViewPager(viewPager);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
 
Example 5
Source File: MainFragment.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(
                R.layout.fragment_main, container, false);

        Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
        ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

        final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.ic_menu);
        ab.setDisplayHomeAsUpEnabled(true);

        if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) == PackageManager.PERMISSION_GRANTED) {

            requestPermissions();

        }
        
//        audioVisualization = (AudioVisualization) rootView.findViewById(R.id.visualizer);
//        audioVisualization.linkTo(DbmHandler.Factory.newVisualizerHandler(getContext(), 0));
        viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
        if (viewPager != null) {
            setupViewPager(viewPager);
            viewPager.setOffscreenPageLimit(2);
        }

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
        tabLayout.setupWithViewPager(viewPager);

//        tabLayout.getTabAt(0).setIcon(R.drawable.ic_audiotrack_white_24dp);
//        tabLayout.getTabAt(1).setIcon(R.drawable.ic_album_white_24dp);
//        tabLayout.getTabAt(2).setIcon(R.drawable.ic_sentiment_satisfied_white_24dp);

        return rootView;

    }
 
Example 6
Source File: DemoActivity.java    From ExpandableTextView with Apache License 2.0 4 votes vote down vote up
private void setupTabLayout(TabLayout tabLayout) {
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setupWithViewPager(mViewPager);
}