How to put a scroll inside tabHost (asbas) on Android?

Asked

Viewed 66 times

1

I have a code that creates tabs on the screen as needed, the problem is that when I create a lot of tabs they get "squeezed" on the screen and cuts the rest on the tabs. I’m doing this all via Java, without using xml so I’m not getting to make my scroll work, does anyone know how I can do this? Thank you in advance.

My shorthand code:

My class inherits from a Tabactivity I’m not using hs = new HorizontalScrollView(this); in the first line inside the code. I tried to use more did not work.

public void adicionaAbas(String texto) {

    hs = new HorizontalScrollView(this);

    TabHost th = getTabHost();

    th.setBackgroundColor(Color.WHITE);

    TabSpec ts = th.newTabSpec(texto);
    // nome da aba
    ts.setIndicator(texto);


    th.addTab(ts);

    setContentView(th);
}
  • What do you mean they are "squeezed"? They are all in the left corner of the screen? Could you post an image? With more details I can help you.

  • For example, my canvas is 9 cm wide, when there are 3 tabs, each one occupies 3 cm, but of 18 tabs, each one will occupy 0.5 cm and will "cut" the text of the tab. with the scroll, they would be the size needed to appear the text. To make it easy in xml, the problem is that I’m not getting to do code.

1 answer

0

I think you should adjust the size of the Scrollview.

ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
hs.setLayoutParams(params);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.