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.
Related
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!
i am new to android and had create the tabhost with two tabwidget all thing goes ok and fine and now i am displaying two different activity with two tab also.but the question is the text which i am specifying for two different tab is coming below while running the app.Below i am putting the screenshot for understanding
Screenshot:
the text are mark as red so is there any way to align that text to the center.
one more thing i m also using the drawable image for different state of user click.
thanks for any help.
the xml file for the tabhost
<?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"
>
<include layout="#layout/top_portion_layout"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
>
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080">
</FrameLayout>
</LinearLayout>
</TabHost>
the portion is another layout which having two button sync all and home
which i am including in this layout
inspite of
android:textAlignment="center"
you should use
android:gravity="center"
android:layout_gravity="center_vertical"
inside tab_host element
I want to display a tab at bottom of screen , so i use
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#android:id/tabcontent" />
</RelativeLayout>
</TabHost>
but also want to display a button below tab widget . At bottom of screen , we have a button and a tab widget which is above button but should be at bottom of screen .
There is any way for doing it.
Please suggest me usable link or sample code.
use linear-layout and put the tabhost and button in it
I am not sure but take one Linear or Relative Layout.
Put TabHost first and then put a button in that new Layout below TabHost.
I have not used it but I think it will work
Im developing an android-app which is basicly three tabs each tab with its own activity class. Here is the main.xml:
<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="0dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp">
<include layout="#layout/sorted_teams" />
<include layout="#layout/unsorted_teams" />
<include layout="#layout/about" />
</FrameLayout>
</LinearLayout>
</TabHost>
I have three includes each with its own activity class and layout xml file. What I want is a scroll on the content of each tab. How would you go about this? I tried enclosing the entire content of the layout files for the different tabs with a scrollview. I use tablelayout for the content of every tab. I tried eclosing the entire content with a scrollview but it wont show up. How would you recommend using scrollview if I want the content scrollable for each tab?
Use a ScrollView as the enclosing parent of TableLayout in each layout file of each of your tab activities.
Make sure your scroll-view definition is similar to
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent">
Thank you for the quick answer! The solution you posted was my solution too but I had missed one detail that seemed to screw everyting up.
I tried again with enclosing everyting with a scrollview in each layout but I had fill_parent on layout_height, changing it to wrap_content seemed to fix everything, problem solved!
I dont know why we set it to fill_parent, I think it was because some issue with the background color.
Hi
I am an android user. I have content listing page and i completed it successfully. But the problem is i have to put two tab on the footer and the footer tab should remain permanently. I also done so many searches to fix this issue bu cannot find the solution. Anybody please help me.
Thanks,
Anoop
Do want to try to add header and footer to list view? then please check the addHeader in list view .check out this link
I have implement it,if need then i will post the code
You need to use a TabHost with the TabWidget underneath the FrameLayout inside a RelativeLayout instead of a LinearLayout, as follows
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:layout_alignParentTop="true"
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>