Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:29:47+00:00 2026-05-26T20:29:47+00:00

I am implementing tab layout in android. I am able to implement tabs however

  • 0

I am implementing tab layout in android. I am able to implement tabs however my implementation gives following output:

enter image description here

In this image, text “Tab 1” “Tab 2” “Tab 3” all are written at the bottom in tab. I want it to write on the top. I have already used android:gravity="top" as well as android:layout_gravity="top" but there did nothing for me. please help. i am using following layout:

    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp"
         android:gravity="top"
           android:layout_gravity="top"
        >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:gravity="top"
            android:layout_gravity="top"
            />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:29:47+00:00Added an answer on May 26, 2026 at 8:29 pm

    We can achieve this by setting TabSpec content with customized views.Here is the sample.

    in main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@android:id/tabhost" android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent" android:layout_height="fill_parent">
                <View android:layout_width="fill_parent" android:layout_height="0.5dip"
                    android:background="#000" />
                <TabWidget android:id="@android:id/tabs"
                    android:layout_width="fill_parent" android:layout_height="wrap_content"
                    android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
                <View android:layout_width="fill_parent" android:layout_height="2dip"
                    android:background="#696969" />
                <View android:layout_width="fill_parent" android:layout_height="2dip"
                    android:background="#000" />
                <FrameLayout android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent" android:layout_height="fill_parent" />
            </LinearLayout>
        </TabHost>
    
    </LinearLayout>
    

    in tabs_bg.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tabsLayout" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:background="@drawable/tab_bg_selector"
        android:padding="10dip" android:gravity="center" android:orientation="vertical">
    
        <TextView android:id="@+id/tabsText" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Title"
            android:textSize="15dip" android:textColor="@drawable/tab_text_selector" />
    </LinearLayout>
    

    i use some custom selector for view, you can create on your own.

    In activity Main.class,

    private TabHost mTabHost;
    
    private void setupTabHost() {
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();
    }
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // construct the tabhost
        setContentView(R.layout.main);
    
        setupTabHost();
        mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    
        setupTab(new TextView(this), "Tab 1");
        setupTab(new TextView(this), "Tab 2");
        setupTab(new TextView(this), "Tab 3");
    }
    
    private void setupTab(final View view, final String tag) {
        View tabview = createTabView(mTabHost.getContext(), tag);
    
        TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
            public View createTabContent(String tag) {return view;}
        });
        mTabHost.addTab(setContent);
    
    }
    
    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }
    

    which provide output like this…enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are trying to implementing Tab Layout in android. I have take the refernce
i need to implement this layout in android..the view must be have two list
I have a question that I am implementing a tab bar in my android
I have a question about the implementation of a ListView layout within a tab
Hi, I'm implementing a layout with Extjs 4 as shown in the image. The
I am new to Android. I am implementing coding related to tab host. I
I am struggling to find a way of implementing a tab style menu system
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
Implementing the ScriptControlClass was extremely easy, unfortunately the side effects with the language implementation
implementing publishActivity in PHP using the REST API using this code: $activity = array(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.