读书人

又遇到控件有关问题tabhost如何用的

发布时间: 2013-04-21 21:18:07 作者: rapoo

又遇到控件问题,tabhost怎么用的啊,求大神
我就高了个简单的tabhost,结果运行什么都没有只看见两个TextView
这是我的布局文件


android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

</LinearLayout>

<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>

<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>

</LinearLayout>


这是我的类文件

package com.example.tabhost;

import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.TabHost;

public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabhost=getTabHost();
tabhost.setup();
setContentView(R.layout.activity_main);
LayoutInflater inflater_tab1 = LayoutInflater.from(this);
inflater_tab1.inflate(R.layout.activity_main, tabhost.getTabContentView(),true);
tabhost.addTab(tabhost.newTabSpec("tab_test1").setIndicator("TAB a").setContent(R.id.tab1));
tabhost.addTab(tabhost.newTabSpec("tab_test2").setIndicator("TAB b").setContent(R.id.tab2));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

真的很想知道是什么原因,我刚刚在学android


[解决办法]
对android不是很懂

读书人网 >Java相关

热点推荐