tab bar hiding issue android

陌路散爱 提交于 2019-12-07 08:45:45

问题


I'm new to android,I'm using tabHost adding some tabs to it,its working quite fine but when i rotate my device in landscape mode it also work there fine but i don't need tab bar there because it covers much space and i also have google ads so both of them cover half of the screen and leave a little space for user to interact.All i need is a solution to somehow hide tab bar just like we can do it in iphone to make a bit room for user to interact.I need some solution urgent.Thanks


回答1:


I think you should wrap your tab widget in any ViewGroup such as LinearLayout or RelativeLayout, and create a static function in your tabActivity to show/hide this wrapper, Here's a little code might be helpful for you.

<LinearLayout
        android:id="@+id/popupTabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone">
        <TabWidget android:id="@android:id/tabs"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"></TabWidget>
    </LinearLayout>

Now your tab activity should do something like this.

public class TabsView extends TabActivity { 
    public static LinearLayout popupTabs ;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        popupTabs = (LinearLayout) findViewById(R.id.popupTabs);

        // Your other code
        //............
        //............
    }

    // Show Tabs method
    public static void showTabs(){
        popupTabs.setVisibility(ViewGroup.VISIBLE);
    }

    // Hide Tabs method
    public static void hideTabs(){
        popupTabs.setVisibility(ViewGroup.GONE);
    }

}

Now you can call this method statically from any location in your code like this

// hide tab from any activity
TabsView.showTabs();

// hide tab from any activity
TabsView.hideTabs()



回答2:


For Hide

mTabHost.getTabWidget().setVisibility(View.GONE);

For Visible

mTabHost.getTabWidget().setVisibility(View.VISIBLE);



回答3:


The simplest way would be to create a second version of your layout.xml file which doesn't include the TabHost and put it in a resource folder named 'layout-land' (the 'land' suffix is short for 'landscape'). Please see this SDK article for more information.




回答4:


Apart from doing what Reuben is telling you would be to animate the transition between both so that the change would be a bit smoother.



来源:https://stackoverflow.com/questions/3987596/tab-bar-hiding-issue-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!