Android: Tabs at the BOTTOM

后端 未结 10 2150
长发绾君心
长发绾君心 2020-11-22 05:03

I\'ve seen some chatter about this, but nothing definite. Is there a way to put the tabs in a TabWidget to the bottom of the screen? If so, how?

I\'ve tried the fol

相关标签:
10条回答
  • 2020-11-22 05:07

    There is a way to remove the line.

    1) Follow this tutorial: android-tabs-with-fragments

    2) Then apply the RelativeLayout change that Leaudro suggested above (apply the layout props to all FrameLayouts).

    You can also add an ImageView to the tab.xml in item #1 and get a very iPhone like look to the tabs.

    Here is a screenshot of what I'm working on right now. I still have some work to do, mainly make a selector for the icons and ensure equal horizontal distribution, but you get the idea. In my case, I'm using fragments, but the same principals should apply to a standard tab view.

    enter image description here

    0 讨论(0)
  • 2020-11-22 05:07

    For all those of you that try to remove the separating line of the tabWidget, here is an example project (and its respective tutorial), that work great for customizing the tabs and thus removing problems when tabs are at bottom. Eclipse Project: android-custom-tabs ; Original explanation: blog; Hope this helped.

    0 讨论(0)
  • 2020-11-22 05:07

    This may not be exactly what you're looking for (it's not an "easy" solution to send your Tabs to the bottom of the screen) but is nevertheless an interesting alternative solution I would like to flag to you :

    ScrollableTabHost is designed to behave like TabHost, but with an additional scrollview to fit more items ...

    maybe digging into this open-source project you'll find an answer to your question. If I see anything easier I'll come back to you.

    0 讨论(0)
  • 2020-11-22 05:12

    Here's the simplest, most robust, and scalable solution to get tabs on the bottom of the screen.

    1. In your vertical LinearLayout, put the FrameLayout above the TabWidget
    2. Set layout_height to wrap_content on both FrameLayout and TabWidget
    3. Set FrameLayout's android:layout_weight="1"
    4. Set TabWidget's android:layout_weight="0" (0 is default, but for emphasis, readability, etc)
    5. Set TabWidget's android:layout_marginBottom="-4dp" (to remove the bottom divider)

    Full code:

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:layout_weight="1"/>
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:layout_marginBottom="-4dp"/>
    
        </LinearLayout>
    
    </TabHost>
    
    0 讨论(0)
  • 2020-11-22 05:14

    Yes, see: link, but he used xml layouts, not activities to create new tab, so put his xml code (set paddingTop for FrameLayout - 0px) and then write the code:

    public class SomeActivity extends ActivityGroup {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
    
        TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host); 
    
        tab_host.setup(this.getLocalActivityManager());
    
        TabSpec ts1 = tab_host.newTabSpec("TAB_DATE"); 
        ts1.setIndicator("tab1"); 
        ts1.setContent(new Intent(this, Registration.class)); 
        tab_host.addTab(ts1); 
    
        TabSpec ts2 = tab_host.newTabSpec("TAB_GEO"); 
        ts2.setIndicator("tab2"); 
        ts2.setContent(new Intent(this, Login.class)); 
        tab_host.addTab(ts2); 
    
        TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT"); 
        ts3.setIndicator("tab3"); 
        ts3.setContent(new Intent(this, Registration.class)); 
        tab_host.addTab(ts3); 
    
        tab_host.setCurrentTab(0);      
    
    
    }
    

    }

    0 讨论(0)
  • 2020-11-22 05:15

    Not sure if it will work for all versions of Android (especially those with custom UI stuff), but I was able to remove the gray bar at the bottom by adding

     android:layout_marginBottom="-3dp"
    

    to the TabWidget XML...

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