Why is my TabHost's FrameLayout's only child loaded with visibility = View.GONE?

后端 未结 1 1147
借酒劲吻你
借酒劲吻你 2021-01-21 22:54

I\'m using a TabHost to render some tabs. In the XML definition everything is set up ~normally, a RelativeLayout is the only child of the FrameLayout for the TabHost.

W

相关标签:
1条回答
  • 2021-01-21 23:46

    I ended up spending some time reading TabHost.java and discovered what was happening.

    • TabHost.java (naively IMO ;) ) assumes that different tabs are attached to different content views.

    • Every time a content view is added to a TabSpec the visibility of the view is set to GONE.

    • Every time a TabSpec is added to the TabHost, the TabHost switches to tab 0.

    • Every time setCurrentTab is called the visibility of the View of that tab is set to VISIBLE if and only if the newly selected tab is not the current tab.

    When a bunch of tabs are added for the same view:

    • first the view is added and its visibility is set to GONE,
    • then the TabHost switches to tab 0 and sets the view's vis to VISIBLE,
    • then the next tab is added and its view (the same view!) has its vis set to GONE,
    • then the TabHost switches to tab 0 which is a ~noop because tab 0 was previously selected so the view isn't switched back to VISIBLE.

    So this was caused by using the same view for the content of multiple tabs.

    So, to fix this call: tabHost.getCurrentView().setVisibility(View.VISIBLE); ... after adding all the tabs

    0 讨论(0)
提交回复
热议问题