2
October
2012
Hello
Small live tip of the Android Initiation advanced training happening in Paris on 01-02-03 October.
I have a trainee Romain Zanon, who wondered how to ensure having a TabHost with the tab bar that scrolls. There are two choices, either is a library that makes it (at the risk of being linked to a dark developer who will never be its lib updating and that potentially has all rotten code), is it pondered a few seconds.
First of all, remember the code to display tabs:
The XML for the layout is as follows:
"" < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android".
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ".
"android:orientation =" vertical ">
< TabHost
Android:id =»@+id/tabhost.
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ">
< LinearLayout
"xmlns:android =" http://schemas.android.com/apk/res/android ".
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ".
"android:orientation =" vertical ">
< 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 ">
< DigitalClock
Android:id =»@+id/digital.
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ".
"android:gravity =" center "/ >
< AnalogClock
Android:id =»@+id/analog.
"android:layout_width =" fill_parent ".
"android:layout_height =" wrap_content ".
"android:layout_gravity =" center "/ >
<!-... of other tabs... - >
< /FrameLayout >
< /LinearLayout >
< /TabHost >
< /LinearLayout >
Okay, then how I do to have the tabs parading? o? I can go in great code hacks, all that, but I can also do very simple, I need to place my tab bar in a HorizontalScrollView and it will scroll automatically.
The code:
"" < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android".
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ".
"android:orientation =" vertical ">
< TabHost
Android:id =»@+id/tabhost.
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ">
< LinearLayout
"xmlns:android =" http://schemas.android.com/apk/res/android ".
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ".
"android:orientation =" vertical ">
< HorizontalScrollView
"android:layout_width =" fill_parent ".
"android:layout_height =" wrap_content ">
< TabWidget
Android:ID =»@android:id/tabs.
"android:layout_width =" wrap_content ".
"android:layout_height =" wrap_content "/ >
< /HorizontalScrollView >
< FrameLayout
Android:ID =»@android:id/tabcontent.
"android:layout_width =" fill_parent ".
"android:layout_height =" fill_parent ">
< DigitalClock
Android:id =»@+id/digital.
"android:layout_width =" wrap_content ".
"android:layout_height =" fill_parent ".
"android:background =" #AA00F0FF ".
"android:gravity =" center "/ >
< AnalogClock
Android:id =»@+id/analog.
"android:layout_width =" fill_parent ".
"android:layout_height =" wrap_content ".
' android:layout_gravity =' center '.
"android:background =" #AAFF00FF "/ >