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));
}
}



效果圖:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM