Android TabView 详解一

直接看代码:

布局代码tab.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent" >


<LinearLayout
android:id="@+id/linearLayout_red"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:orientation
="vertical" >
<Button
android:id="@+id/button1"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="bt1" />

</LinearLayout>


<LinearLayout
android:id="@+id/linearLayout_blue"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:orientation
="vertical" >
<Button
android:id="@+id/button2"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="bt2" />

</LinearLayout>


<LinearLayout
android:id="@+id/linearLayout_green"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:orientation
="vertical" >

<Button
android:id="@+id/button3"
android:layout_width
="wrap_content"
android:layout_height
="wrap_content"
android:text
="bt3" />



</LinearLayout>

</FrameLayout>

java源码:

public class TabTest extends TabActivity {
/** Called when the activity is first created. */
private TabHost myTabhost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myTabhost=this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.tab, myTabhost.getTabContentView(), true);
myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));

myTabhost.addTab(myTabhost.newTabSpec("One")
.setIndicator("A",
getResources().getDrawable(R.drawable.gimp))
.setContent(R.id.linearLayout_red));
myTabhost.addTab(myTabhost.newTabSpec("Two")
.setIndicator("B",
getResources().getDrawable(R.drawable.mumule))
.setContent(R.id.linearLayout_blue));
myTabhost.addTab(myTabhost.newTabSpec("Three")
.setIndicator("C",
getResources().getDrawable(R.drawable.notepad))
.setContent(R.id.linearLayout_green));
}
}



效果图:

posted @ 2012-01-17 17:09  古老的陶罐  阅读(10762)  评论(3)    收藏  举报