Friday, 18 January 2013

Tabs Demo - General Way

Screen Shots:







1.main.xml:


<?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="wrap_content" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/tab1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="60dp" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="This is Tab 1" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/one" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tab2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="60dp" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="This is Tab 2" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/two" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/tab3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:paddingTop="60dp" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="This is Tab 3" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/three" />
        </LinearLayout>
    </FrameLayout>

</TabHost>

2.Activity:

package com.venkool.tabsdemo;



import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabsDemoActivity extends Activity {
      /** Called when the activity is first created. */

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
            tabHost.setup();

            TabSpec spec1 = tabHost.newTabSpec("Tab1");
            spec1.setIndicator("Tab1");
            spec1.setContent(R.id.tab1);

            TabSpec spec2 = tabHost.newTabSpec("Tab2");
            spec2.setIndicator("Tab2");
            spec2.setContent(R.id.tab2);

            TabSpec spec3 = tabHost.newTabSpec("Tab3");
            spec3.setIndicator("Tab3");
            spec3.setContent(R.id.tab3);

            tabHost.addTab(spec1);
            tabHost.addTab(spec2);
            tabHost.addTab(spec3);
      }
}

No comments:

Post a Comment