TabHost里面怎么添加控件
xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcc00">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<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="wrap_content"
>
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蔬菜"/>
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水果"/>
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="儿歌"/>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
java代码:
package com.example.study;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class lei extends Activity{
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lei);
tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("蔬菜").setIndicator("蔬菜",
getResources().getDrawable(R.drawable.ic_launcher)).setContent(
R.id.t1));
tabHost.addTab(tabHost.newTabSpec("水果").setIndicator("水果")
.setContent(R.id.t2));
tabHost.addTab(tabHost.newTabSpec("儿歌").setIndicator("儿歌")
.setContent(R.id.t3));
}
}
我写的如上面的代码,实现了一个有三个tab的TabHost,怎么往Tab里面加入控件。
加入“水果”“蔬菜”的图片和“儿歌”。求解答!最好给个例子。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcc00">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<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="wrap_content"
>
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蔬菜"/>
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水果"/>
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="儿歌"/>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
java代码:
package com.example.study;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class lei extends Activity{
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lei);
tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("蔬菜").setIndicator("蔬菜",
getResources().getDrawable(R.drawable.ic_launcher)).setContent(
R.id.t1));
tabHost.addTab(tabHost.newTabSpec("水果").setIndicator("水果")
.setContent(R.id.t2));
tabHost.addTab(tabHost.newTabSpec("儿歌").setIndicator("儿歌")
.setContent(R.id.t3));
}
}
我写的如上面的代码,实现了一个有三个tab的TabHost,怎么往Tab里面加入控件。
加入“水果”“蔬菜”的图片和“儿歌”。求解答!最好给个例子。
...全文
相关推荐
Android 控件之TabHost Tab页
Android 控件之TabHost Tab页
Android studio TabHost应用设计
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("标签页一").setContent(R.id.tab1));tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("标签页三").setContent(R.id.tab3));android:text="tab 1 的布局"android:text="tab 2 的布局"android:text="tab 3 的布局"
android tab控件使用
android tab控件的简单使用,适合新手
Android TabHost控件讲解
这份Pdf文档主要讲解了TabHost控件的使用方法,希望对菜鸟们有帮助
Fragment实现底部tabhost的效果
利用fragment片段实现tabhost切换界面的功能,带有自定义控件和通过代码加载布局的方法



