Is it possible to create Horizontal Tabs in Android OS? - android

I'm using the TabHost and TabWidget to create some tabs for an Android application. I see that the tabs show up vertically one next to the other. Is there any way to make tabs that are aligned horizontally (one on top of the other) ?.
I'm creating the tabs like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a tab" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
</FrameLayout>
</LinearLayout>
Something like this is what I need to do:

Try this one: https://code.google.com/p/themissingtabwidget/ . This is an open-source implementation based on the original tab widget that also works in horizontal mode.

I'm not certain, but I don't think there's much you can do with the default behavior. Android's tab support in general seems a bit clunky to me. But let me know if you do get this working -- I might be able to use it myself!
FWIW, I did my own tab behavior using image buttons and other control elements. In my case, I was trying to come up with tabs that didn't use so much screen real estate.

Related

Robust way to implement "bottom navigation tab bar"

The effect is like this:
I have investigated some methods.
Somebody use radiogroup, somebody use tabhost.
What is the simplest way?
Is there any other way?
It is not really what google recommends in there Design Guidelines for tabs, if you still want to use it, i think TabHost is the perfect way.For more see How to align your TabHost at the bottom of the screen
<?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">
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</RelativeLayout>
</TabHost>
Check out this link which contains library and sample codes for each type of tab (i.e circle, underline, etc)
Using this library, You can implement different type of tab format. Your work is just import this library into your app.
And, Samples will help you to understand the different tab format.
All the Best!

Arranging big number of tabs in Android

Good time!
My question is concerned to the arrange of tabs in Android apps. My app consisted 6 pages of tabs and, sure, in the running application these tabs decrease to the narrow rectangles - that's really looks bad. So, is there any cases to switch on some features in tabs to add controls with arrows (like in Windows), which are used to manage the visibility of concrete tab. For example, I have six tabs, after start user sees only three and some control to move hidden tabs on screen?
Yehh...... I think you don't need to use narrow rectangles to complete your task. You have better solution to put your TabView in ScrollView.
For example :
<?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">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
Refrence : Scrolling Tabs in Android
In order to ease your life, you can use a FrameLayout and on top of the TabWidget you can add a HorizontalScrollView with any number of buttons you want.
Then using the onClick method, when you click a specific button of this HorizontalScrollView, you can set the current tab of your activity.
This way you can also have easy theming to your "tabs"... Hope this helps.

Android Tabs in XML

My question is simple. Is it possible to create tabs entirely in xml? My app has only one activity. I want to have 2 tabs that show the same data but in slightly different layouts. It seems like it should be but I cannot find anything on it.
TIA,
Mark
You can do something like this. Your layout for each tab would go inside a tabwidget. This will have it's limitations that you would easily get around if you employ a simple TabHost
<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">
<!-- Tabs at bottom of screen -->
<TabWidget
android:background="#drawable/textview_top"
android:layout_weight="12"
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="0dip"
/>
</TabHost>

Scrolling Tabhost at the bottom

I used the tabhost tutorial to get started with the Tabhost control.
After some play around I wanted to make the tabhost scrollable, which I figured out.
Now I want the tabhost at the bottom of the display which is just not working for me.
Switched to Relative Layout which was suggested here: iPhone-like Tabbar
My code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal" android:isScrollContainer="true">
<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" android:layout_alignParentBottom="true">
<RelativeLayout android:layout_height="fill_parent"
android:layout_width="fill_parent">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="none"
android:layout_alignParentBottom="true">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="2dp" />
</RelativeLayout>
</TabHost>
I need a hint why it's not working / how this would work. I tried with relative layout and layout_alignParentBottom="true" now it's there a few times (in the HorizontalScrollView and the TabWidget)
Thanks to Arve leading me to "custom controls" I found a promising project:
https://github.com/honcheng/ScrollableTabHost-for-Android
I hope some others looking for this kind of tabhost can use it :)
A possible library to help you do this:
http://code.google.com/p/androidtabs/
From their project description:
Due to limitation of Android Tab component I created a custom TabWidget that I am using in couple different projects already. The widget allows us to add custom background and use custom icons, tabs can be Top/Bottom aligned.
EDIT: I have not tested this myself, but it looks promising.

how to scroll the tabs in tabview

I am using six tabs in tab view. In portrait mode tab size become very small .So i want to scroll the tabs in horizontal so that size of each tab will remain original . How we can do this?
Is this what you are looking for? http://blog.uncommons.org/2011/04/18/scrolling-tabs-in-android/
There are a lot of solutions on the web for this but they're all complicated and unnecessary. If you are trying to make the tabs on the top of the screen scroll-able then you can use this simple implementation I have shown below. Hope this helps.
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>

Categories

Resources