开发者

Tab contents are overlapping in android application

开发者 https://www.devze.com 2023-02-09 18:25 出处:网络
I have a TabActivity to show two list, one list in each tab. While starting the application the contents of two tabs are shown as overlapping. But when the other tab is selected then its working prope

I have a TabActivity to show two list, one list in each tab. While starting the application the contents of two tabs are shown as overlapping. But when the other tab is selected then its working properly. Please help me

My code is:

@Override
public void onCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );   
    setContentView( R.layout.tab_layout );
    Resources res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost();
    tabHost.setOnTabChangedListener( this );

    // setup list view 1
    listView1 = ( ListView ) findViewById( R.id.list1 );

    // setup list view 2
    listView2 = ( ListView ) findViewById( R.id.list2 );


    // add views to tab host
    tabHost.addTab( tabHost.newTabSpec( LIST1_TAB_TAG ).setIndicator( LIST1_TAB_TAG,
            res.getDrawable( R.drawable.rupees ) ).setContent( new TabCont开发者_开发百科entFactory()
    {
        public View createTabContent( String arg0 )
        {
            return listView1;
        }
    } ) );
    tabHost.addTab( tabHost.newTabSpec( LIST2_TAB_TAG ).setIndicator( LIST2_TAB_TAG,
            res.getDrawable( R.drawable.food ) ).setContent( new TabContentFactory()
    {
        public View createTabContent( String arg0 )
        {
            return listView2;
        }
    } ) );
    // Set listener for list1
    listView1.setOnItemClickListener( new OnItemClickListener()
    {
        public void onItemClick( AdapterView parent, View view, int position, long id )
        {
            onListItemClick( id );
        }
    } );
    // Set listener for list2
    listView2.setOnItemClickListener( new OnItemClickListener()
    {
        public void onItemClick( AdapterView parent, View view, int position, long id )
        {
            onListItemClick( id );
        }
    } );
    listView2.setVisibility( View.INVISIBLE );
}


The conclusion I came to was that the TabHost will assume everything's already invisible. When you select the initial tab, it will merely show it. Thus, if you set all of your views to invisible you should be fine. I simply set the view (in my case a simple TextView for now) to invisible before constructing the appropriate TabContentFactory.

0

精彩评论

暂无评论...
验证码 换一张
取 消