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]));
}
还有一个就是图片大小的问题,怎么使得根据屏幕的大小 来调整图片的大小;