Demo:
1)Tabs Activity:
1)Tabs Activity:
package
com.venky.tabsdemo1;
import
android.app.Activity;
import
android.os.Bundle;
import
android.widget.TabHost;
import
android.widget.TabHost.TabSpec;
public class TabsDemo1 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);
}
}
2)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>
3)Download this project Click Here
very good
ReplyDelete