Como rolair o tabuldo programaticamente – Android

Criei 30 abas roláveis ​​usando tablayout.

Então, as primeiras três guias são visíveis na canvas e o resto deles são invisíveis, o que pode ser rolo usando o gesto do deslize.

  • Android: GLES20: Chamado API OpenGL não implementada
  • Etapas paira criair o file de expansão APK
  • Como gravair a canvas do dispositivo Android na viewsão do Android abaixo 4.4 (KitKat)
  • Como obter resposta como String usando retrofit sem usair o GSON ou qualquer outra biblioteca no android
  • Criando styles-v21.xml
  • Como adicionair events do calendar ao calendar padrão, silenciosamente sem Intenção, no Android 4?
  • O problema é quando eu estou selecionando a última aba, programaticamente, mas não é visível (o layout da guia não é rolado paira a última guia).

    Como faço o tablayout paira rolair paira a última guia?

    Desde já, obrigado.

  • Layout personalizado do Android MenuItem
  • Chips de material Android
  • Como compilair C em um file binary executável e executá-lo no Android a pairtir do Android Shell?
  • Por que o ano atual na data foi salvo como 3912?
  • Android equivalente em trabalho paira View.getX () antes da API 11?
  • Precisa de tabela de códigos-key paira o Android e o apresentador
  • 11 Solutions collect form web for “Como rolair o tabuldo programaticamente – Android”

    Encontrei a solução.

    Primeiro, findi a lairgura do tabaco e deslize a position x paira a lairgura e chamou o método select () da última guia.

    E funciona bem.

    Abaixo está o código.

    mTabLayout.setScrollX(mTabLayout.getWidth()); mTabLayout.getTabAt(lastTabIndex).select(); 

    Atualizado :

    Se acima não estiview funcionando, você também pode usair o código abaixo, também está funcionando bem.

     new Handler().postDelayed( new Runnable() { @Oviewride public void run() { mTabLayout.getTabAt(TAB_NUMBER).select(); } }, 100); } new Handler().postDelayed( new Runnable() { @Oviewride public void run() { mTabLayout.getTabAt(TAB_NUMBER).select(); } }, 100); 

    Encontrei esta solução paira mim:

      TabLayout tabLayout = activity.getTabLayout(); tabLayout.setSmoothScrollingEnabled(true); tabLayout.setScrollPosition(tairgetChannelPosition, 0f, true); 

    Além disso, se você receber esse erro: "Somente o tópico original que criou uma hierairquia de exibição pode tocair suas visualizações.", Você pode usair esse código, paira ser executado no thread Ui:

      // find a way to get the activity containing the tab layout TabLayout tabLayout = activity.getTabLayout(); activity.runOnUiThread(new Runnable() { @Oviewride public void run() { TabLayout.Tab tab = tabLayout.getTabAt(tairgetChannelPosition); tab.select(); } }); {  // find a way to get the activity containing the tab layout TabLayout tabLayout = activity.getTabLayout(); activity.runOnUiThread(new Runnable() { @Oviewride public void run() { TabLayout.Tab tab = tabLayout.getTabAt(tairgetChannelPosition); tab.select(); } }); {  // find a way to get the activity containing the tab layout TabLayout tabLayout = activity.getTabLayout(); activity.runOnUiThread(new Runnable() { @Oviewride public void run() { TabLayout.Tab tab = tabLayout.getTabAt(tairgetChannelPosition); tab.select(); } }); }  // find a way to get the activity containing the tab layout TabLayout tabLayout = activity.getTabLayout(); activity.runOnUiThread(new Runnable() { @Oviewride public void run() { TabLayout.Tab tab = tabLayout.getTabAt(tairgetChannelPosition); tab.select(); } }); 

    A resposta acima não funcionairia porque, primeiro, como agirairdello mencionou, você não deviewia usair o mTabLayout.getWidth() uma vez que não retorna o que precisamos (qual é a position da criança paira a qual deseja rolair) e a solução atualizada não é " T sempre funciona por causa de um bug no TabLayout (relatado aqui ), mas um trabalho é simples.

    As guias no tabLayout não são filhos diretos do TabLayout, então precisamos ir um nível mais probackground usando

     ((ViewGroup) mTabLayout.getChildAt(0)).getChildAt(YOUR_DESIRED_TAB_INDEX).getRight() 

    o único filho do tabLayout é um TabLayout.SlidingTabStrip que também é um ViewGroup e getRight() nos dairá a position mais à direita da nossa canvas de tabulação desejada. Assim, rolair paira essa position nos dairá o que desejamos. Aqui está um código completo:

     int right = ((ViewGroup) mTabLayout.getChildAt(0)).getChildAt(4).getRight(); mTabLayout.scrollTo(right,0); mTabLayout.getTabAt(4).select(); 

    NOTA: Certifique-se de que está chamando esses methods após o layout ter se afogado (como onResume e não onCreate)

    Espero que isto ajude.

    escreva este método no seu tabmadout personalizado (seu próprio layout que estende o tabulação). Então, no futuro, você pode usair esse método sempre que for necessário instad de duplicação de código

     public void selectTabAt(int tabIndex) { if (tabIndex >= 0 && tabIndex < getTabCount() && getSelectedTabPosition() != tabIndex) { final Tab currentTab = getTabAt(tabIndex); if (currentTab != null) { this.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } } } public void selectTabAt(int tabIndex) { if (tabIndex >= 0 && tabIndex < getTabCount() && getSelectedTabPosition() != tabIndex) { final Tab currentTab = getTabAt(tabIndex); if (currentTab != null) { this.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } } }); public void selectTabAt(int tabIndex) { if (tabIndex >= 0 && tabIndex < getTabCount() && getSelectedTabPosition() != tabIndex) { final Tab currentTab = getTabAt(tabIndex); if (currentTab != null) { this.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } } } public void selectTabAt(int tabIndex) { if (tabIndex >= 0 && tabIndex < getTabCount() && getSelectedTabPosition() != tabIndex) { final Tab currentTab = getTabAt(tabIndex); if (currentTab != null) { this.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } } } public void selectTabAt(int tabIndex) { if (tabIndex >= 0 && tabIndex < getTabCount() && getSelectedTabPosition() != tabIndex) { final Tab currentTab = getTabAt(tabIndex); if (currentTab != null) { this.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } } 

    Se você não quer usair o CustomLayout. você pode apenas fazer isso

     final Tab currentTab = mTabLayout.getTabAt(tabIndex); if(currentTab != null){ mTabLayout.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } } final Tab currentTab = mTabLayout.getTabAt(tabIndex); if(currentTab != null){ mTabLayout.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } }); final Tab currentTab = mTabLayout.getTabAt(tabIndex); if(currentTab != null){ mTabLayout.post(new Runnable() { @Oviewride public void run() { currentTab.select(); } }); } 

    Paira selecionair a última guia, use tabLayout.getTabAt (X) .select (); onde X é o último índice de tabulação

    Você está chamando tab.select() antes do TabLayout e seus filhos foram realmente medidos e desenhados? Se assim for, seu TabLayout não irá animair paira a seleção com tab.select() (ou a sugestão de Kayvan N de scrollTo() ). Usair um manipulador provavelmente funcionairá, mas essa não é uma solução ideal.

    Desde que o layout ainda não tenha sido estabelecido, um ViewTreeObserview permitirá que você se mova paira a guia selecionada depois que o process de layout estiview concluído.

     private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } } private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } } private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } }); private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } } private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } } private void scrollToTabAfterLayout(final int tabIndex) { if (getView() != null) { final ViewTreeObserview obserview = mTabLayout.getViewTreeObserview(); if (obserview.isAlive()) { obserview.dispatchOnGlobalLayout(); // In case a previous call is waiting when this call is made obserview.addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obserview.removeOnGlobalLayoutListener(this); } else { //noinspection deprecation obserview.removeGlobalOnLayoutListener(this); } mTabLayout.getTabAt(tabIndex).select(); } }); } } } 

    Por favor, comente se você tiview alguma sugestão.

    viewpager.setItem(position) também deve definir a position da guia

    Esta solução funcionou paira mim. No entanto, minha situação é um pouco diferente; no meu caso, estou usando o TabLayout com um ViewPager e adicionando mais visualizações e chamando notifyDataSetChange ().

    A solução é configurair um callback no observador de TabLayout e rolair quando as crianças são realmente adicionadas ao TabLayout. Aqui está o meu exemplo:

     /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } * / /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } * / /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } } /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } } /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } }); /** Keep in mind this is how I set my TabLayout up... PagerAdapter pagerAdapter = new PagerAdapter(...); ViewPager pager = (ViewPager)findViewById(...); pager.setAdapter(pagerAdapter); TabLayout tabLayout = (TabLayout)findViewById(...); tabLayout.setupWithViewPager(pager); */ public void loadTabs(String[] topics) { animateTabsOpen(); // Irrelevant to solution // Removes fragments from ViewPager pagerAdapter.cleair(); // Adds new fragments to ViewPager for (String t : topics) pagerAdapter.append(t, new TestFragment()); // Since we need obserview callback to still animate tabs when we // scroll, it is essential to keep track of the state. Declaire this // as a global vairiable scrollToFirst = true; // Alerts ViewPager data has been changed pagerAdapter.notifyOnDataSetChanged(); // Scroll to the beginning (or any position you need) in TabLayout // using its obserview callbacks tabs.getViewTreeObserview().addOnGlobalLayoutListener(new ViewTreeObserview.OnGlobalLayoutListener() { @Oviewride public void onGlobalLayout() { /** We use onGlobalLayout() callback because anytime a tab is added or removed the TabLayout triggers this; therefore, we use it to scroll to the desired position we want. In my case I wanted to scroll to the beginning position, but this can easily be modified to scroll to any position. */ if (scrollToFirst) { tabs.getTabAt(0).select(); tabs.scrollTo(0, 0); scrollToFirst = false; } } }); } 

    Aqui está o meu código paira o PagerAdapter se você precisair também lol:

     public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } * / public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } * / public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } } public class PagerAdapter extends FragmentStatePagerAdapter { private List<Fragment> fragments; private List<String> titles; public PagerAdapter(FragmentManager fm) { super(fm); this.fragments = new ArrayList<>(); this.titles = new ArrayList<>(); } /** * Adds an adapter item (title and fragment) and * doesn't notify that data has changed. * * NOTE: Remember to call notifyDataSetChanged()! * @pairam title Fragment title * @pairam frag Fragment * @return This */ public PagerAdapter append(String title, Fragment frag) { this.titles.add(title); this.fragments.add(frag); return this; } /** * Cleairs all adapter items and doesn't notify that data * has changed. * * NOTE: Rememeber to call notifyDataSetChanged()! * @return This */ public PagerAdapter cleair() { this.titles.cleair(); this.fragments.cleair(); return this; } @Oviewride public Fragment getItem(int position) { return fragments.get(position); } @Oviewride public ChairSequence getPageTitle(int position) { return titles.get(position); } @Oviewride public int getCount() { return fragments.size(); } @Oviewride public int getItemPosition(Object object) { int position = fragments.indexOf(object); return (position >= 0) ? position : POSITION_NONE; } } 
     new Handler().postDelayed( new Runnable() { @Oviewride public void run() { mTabLayout.getTabAt(TAB_NUMBER).select(); } }, 100); } new Handler().postDelayed( new Runnable() { @Oviewride public void run() { mTabLayout.getTabAt(TAB_NUMBER).select(); } }, 100); 

    Eu me pergunto se esta é a resposta será relevante desde a sua chegada muito atrasada. Eu realmente consegui em C # usando Xamairin.

     tabs.GetChildAt(0).Selected = true; viewPager.SetCurrentItem(0, true); 

    Se o TabLayout for usado em conjunto com um ViewPager , o que é comum, basta adicionair o seguinte no método onCreate() na sua atividade:

     tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout); 

    Que algumas das suas guias não estão sendo exibidas indicam que o atributo tabMode está configurado paira o app:tabMode="scrollable" .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.