Riskhan
Riskhan

Reputation: 4470

How to show tab title fully in android

I am newbie in android. I developed an android application that shows 15 tabs. One problem is i can't see each tab's title fully. Is it tabs in the android is scrollable. I use below code to create tabs. looking for better solution

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
        <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
        <FrameLayout android:layout_width="match_parent" android:layout_height="500px" android:id="@android:id/tabcontent">
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1">
                <TextView android:text="Tab1 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2">
                <TextView android:text="Tab2 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />                   
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">
                <TextView android:text="Tab3 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />                   
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab4">
                <TextView android:text="Tab4 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />                
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab5">
                <TextView android:text="Tab5 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab6">
                <TextView android:text="Tab6 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab7">
                <TextView android:text="Tab7 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab8">
                <TextView android:text="Tab8 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab9">
                <TextView android:text="Tab9 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab10">
                <TextView android:text="Tab10 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab11">
                <TextView android:text="Tab11 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab12">
                <TextView android:text="Tab12 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab13">
                <TextView android:text="Tab13 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab14">
                <TextView android:text="Tab14 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>                
            <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab15">
                <TextView android:text="Tab15 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>
</LinearLayout>

activity class

package mtx.samples;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class NewTabAppActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final AlertDialog.Builder ad = new AlertDialog.Builder(this);

    TabHost tabHost = getTabHost();
    // tab1
    TabSpec ts1 = tabHost.newTabSpec("Tab1");
    ts1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.rss));
    ts1.setContent(R.id.tab1);
    tabHost.addTab(ts1);

    // tab2
    TabSpec ts2 = tabHost.newTabSpec("Tab2");
    ts2.setIndicator("Tab 2");
    ts2.setContent(R.id.tab2);
    tabHost.addTab(ts2);

    // tab3
    TabSpec ts3 = tabHost.newTabSpec("Tab3");
    ts3.setIndicator("Tab 3");
    ts3.setContent(R.id.tab3);
    tabHost.addTab(ts3);

    // tab4
    TabSpec ts4 = tabHost.newTabSpec("Tab4");
    ts4.setIndicator("Tab 4");
    ts4.setContent(R.id.tab4);
    tabHost.addTab(ts4);

    // tab5
    TabSpec ts5 = tabHost.newTabSpec("Tab5");
    ts5.setIndicator("Tab 5");
    ts5.setContent(R.id.tab5);
    tabHost.addTab(ts5);

    // tab6
    TabSpec ts6 = tabHost.newTabSpec("Tab6");
    ts6.setIndicator("Tab 6");
    ts6.setContent(R.id.tab6);
    tabHost.addTab(ts6);

    // tab7
    TabSpec ts7 = tabHost.newTabSpec("Tab7");
    ts7.setIndicator("Tab 7");
    ts7.setContent(R.id.tab7);
    tabHost.addTab(ts7);

    // tab8
    TabSpec ts8 = tabHost.newTabSpec("Tab8");
    ts8.setIndicator("Tab 8");
    ts8.setContent(R.id.tab8);
    tabHost.addTab(ts8);

    // tab9
    TabSpec ts9 = tabHost.newTabSpec("Tab9");
    ts9.setIndicator("Tab 9");
    ts9.setContent(R.id.tab9);
    tabHost.addTab(ts9);

    // tab10
    TabSpec ts10 = tabHost.newTabSpec("Tab10");
    ts10.setIndicator("Tab 10");
    ts10.setContent(R.id.tab10);
    tabHost.addTab(ts10);

    // tab11
    TabSpec ts11 = tabHost.newTabSpec("Tab11");
    ts11.setIndicator("Tab 11");
    ts11.setContent(R.id.tab11);
    tabHost.addTab(ts11);

    // tab12
    TabSpec ts12 = tabHost.newTabSpec("Tab12");
    ts12.setIndicator("Tab 12");
    ts12.setContent(R.id.tab12);
    tabHost.addTab(ts12);

    // tab13
    TabSpec ts13 = tabHost.newTabSpec("Tab13");
    ts13.setIndicator("Tab 13");
    ts13.setContent(R.id.tab13);
    tabHost.addTab(ts13);

    // tab14
    TabSpec ts14 = tabHost.newTabSpec("Tab14");
    ts14.setIndicator("Tab 14");
    ts14.setContent(R.id.tab14);
    tabHost.addTab(ts14);

    // tab15
    TabSpec ts15 = tabHost.newTabSpec("Tab15");
    ts15.setIndicator("Tab 15");
    ts15.setContent(R.id.tab15);
    tabHost.addTab(ts15);


    ad.setTitle("NewTabApp");
    ad.setNeutralButton("OK", null );

    Button btnSendSettings = (Button)findViewById(R.id.btnSendSettings);
    btnSendSettings.setOnClickListener( new View.OnClickListener() {

        public void onClick(View v) {
            ad.setMessage("Send Settings button Clicked");
            ad.show();
        }
    });

    Button btnClose = (Button)findViewById(R.id.btnClose);
    btnClose.setOnClickListener( new View.OnClickListener() {

        public void onClick(View v) {
            System.exit(-1);
        }
    });

    Button btnSave = (Button)findViewById(R.id.btnSave);
    btnSave.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            ad.setMessage("Save button Clicked");
            ad.show();              
        }
    });

    Button btnSend = (Button)findViewById(R.id.btnSend);
    btnSend.setOnClickListener( new View.OnClickListener() {

        public void onClick(View v) {
            ad.setMessage("Send button Clicked");
            ad.show();              
        }
    });
}
 }

Upvotes: 1

Views: 1650

Answers (1)

Dinesh Sharma
Dinesh Sharma

Reputation: 11571

you can make scrolling tabs in android using HorizontalScrollView in your layout xml file .

<HorizontalScrollView android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:fillViewport="true"
                          android:scrollbars="none">
      <TabWidget android:id="@android:id/tabs"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"/>
    </HorizontalScrollView>

For reference go through the link :

scrolling-tabs-android

Hope this will help you to solve your issue.

Upvotes: 5

Related Questions