Gokul
Gokul

Reputation: 1

Tab Host height in android

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {

            Log.v("","tabhost...");
            Log.v("","tabHost.getTabWidget().getChildAt(i).getLayoutParams() " +tabHost.getTabWidget().getChildAt(i));
            RelativeLayout relativeLayout = (RelativeLayout)tabHost.getTabWidget().getChildAt(i);
            relativeLayout.getChildCount();
            Log.v("","count  "+relativeLayout.getChildCount()+"   relativeLayout.getChildAt(i) "+relativeLayout.getChildAt(i));
            TextView tabhostText = (TextView) relativeLayout.getChildAt(1);

            tabhostText.setTextSize(20.0f);
            tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 30;

        }

In the above code everything is working fine i.e., i am able to see the Text on the tab. But i am not able to see the text in the Device. only some part of the text is visible. please could any body find some solution.

Thanks in advance..

Upvotes: 0

Views: 3586

Answers (2)

Bit-World
Bit-World

Reputation: 11

I found solution.

View v = getLayoutInflater().inflate(R.layout.tab_header, null);
tabSpec.setIndicator(v);

Just use custom layout for tabs.

Upvotes: 1

Kyle Clegg
Kyle Clegg

Reputation: 39480

I know your question is 10 months old now, but the reason only part of the text is visible is because you set the height to just 30. The default on your phone is probably 96 pixels (or maybe 64 if your phone has lower res).

If you want to make your code more universal, you can get the height of the tabs first, then set the height of each tab to a percentage of the original height. In the example below I set the height of the tabs to 80% of the original height.:

    double height = tabHost.getTabWidget().getChildAt(0).getLayoutParams().height;

    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {

                RelativeLayout relativeLayout = (RelativeLayout)tabHost.getTabWidget().getChildAt(i);
                TextView tabhostText = (TextView) relativeLayout.getChildAt(1);

                tabhostText.setTextSize(20.0f);
                tabHost.getTabWidget().getChildAt(i).getLayoutParams().height =  (int) (0.8 * height);

            }

p.s. You may want to word your question better next time. I think I understand what you're asking, but only because I'm working on the exact same thing. Try wording your question in normal question form (e.g. ending with a question mark).

Upvotes: 1

Related Questions