-1

大家好,我正在使用 TabHost 在 android 中创建 TabBar....

    public class TabBarActivity extends TabActivity implements OnTabChangeListener
{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab);

        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        Intent intent;

        intent = new Intent().setClass(this, CustomizedListView.class);
        spec = tabHost.newTabSpec("Clubs").setIndicator("Clubs", getResources().getDrawable(R.drawable.clubs_icon))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Events.class);
        spec = tabHost.newTabSpec("Events").setIndicator("Events", getResources().getDrawable(R.drawable.events_icon))
                      .setContent(intent);
        tabHost.addTab(spec);



        intent = new Intent().setClass(this, Maps.class);
        spec = tabHost.newTabSpec("Maps").setIndicator("Maps", getResources().getDrawable(R.drawable.maps_icon))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Settings.class);
        spec = tabHost.newTabSpec("Settings").setIndicator("Settings", getResources().getDrawable(R.drawable.settings_icon))
                      .setContent(intent);
        tabHost.addTab(spec);

        getTabHost().setOnTabChangedListener(this);
    }

    @Override
    public void onTabChanged(String tabId)
    {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "Inside the new tab ", Toast.LENGTH_SHORT).show();
        //getTabHost().setVisibility(View.VISIBLE);

    }
}

**tab.xml**
        <?xml version="1.0" encoding="utf-8"?>
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <RelativeLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TabWidget
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:id="@android:id/tabs">
            </TabWidget>

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@android:id/tabcontent">
            </FrameLayout>
        </RelativeLayout>
    </TabHost>

but the problem is that whenever the contents of the tab grow eg displaying dynamic content in listview against a tab then the TabHost becomes INVISIBLE..

在这方面的任何帮助将不胜感激....

4

1 回答 1

0

使用 TabActivity 的 Insted 使用普通的 Activity。然后根据您的要求使用 tabspec 创建 TabHost。并将 tabHost 添加为屏幕/活动中的第一个组件。

于 2013-01-16T14:24:54.520 回答