实现美观的TabHost

http://blog.csdn.net/west8623/article/details/7453814

有一个关于关于异常“The specified child already has a parent. You must call removeView"的解决


个人遇到的问题是:


protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabhost=(TabHost)findViewById(R.id.tabhost);
//这里要注意,要启动该tabhost对象
//Call setup() before adding tabs if loading TabHost using findViewById(). However: You do not need to call setup() after getTabHost() 
tabhost.setup();
String []tab={"tab1","tab2","tab3","tab4"};
//四个widget视图,一个视图,需要动态更换图片
View tempview=null;
//四个布局文件的id
int []layout={R.id.tab1,R.id.tab2,R.id.tab3,R.id.tab4};
//定义需要的布局文件
int file[]={R.layout.shou,R.layout.xin,R.layout.yu,R.layout.ke};
View view=LayoutInflater.from(this).inflate(R.layout.other, tabhost.getTabContentView(), true);
for(int i=0;i<4;i++){
//得到视图

System.out.println("i-->"+i);
tempview=LayoutInflater.from(this).inflate(file[i], null);
//将视图填充到表中

//在这里如果代码是tempview=LayoutInflater.from(this).inflate(file[i],tabhost.getTabContentView(), true);就会出错。

                         //不知道这是什么原因啦啦啦,忧伤

tabhost.addTab(tabhost.newTabSpec(tab[i]).setIndicator(tempview).setContent(layout[i]));
// tabhost.addTab(tabhost.newTabSpec(tab[i]).setIndicator(tab[i]).setContent(layout[i]));
}



还有一个就是图片大小的问题,怎么使得根据屏幕的大小 来调整图片的大小;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值