I'm trying to add HorizontalScrollView to FragmentTabHost. I was following 'Lore Giver' answer from FragmentTabHost with horizontal scroll but its not working for me. After implementing xml like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.app.FragmentTabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="@+id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</HorizontalScrollView>
<FrameLayout
android:id="@+id/tabHostContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="48dp" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
And setting it up like this :
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater!!.inflate(R.layout.home_tabs, container, false)
viewContext = view.context
tabHost = view.findViewById(R.id.tabHost)
tabHost.setup(view.context, fragmentManager, R.id.tabHostContent)
tabHost.addTab(tabHost.newTabSpec("home").setIndicator(context!!.getString(R.string.TAB_EMERGENCY)), EmergencyFragment::class.java, null)
tabHost.addTab(tabHost.newTabSpec("friends").setIndicator(context.getString(R.string.TAB_PRIVATE)), PrivateFragment::class.java, null)
tabHost.addTab(tabHost.newTabSpec("organizations").setIndicator(context!!.getString(R.string.ORGANIZATIONS)), OrganizationsFragment::class.java, null)
tabHost.tabWidget.dividerDrawable = null
tabHost.tabWidget.isStripEnabled = false
changeStyleOfSelectedTab()
tabHost.setOnTabChangedListener {
changeStyleOfSelectedTab()
(activity as MainActivity).tabChangedByClick(currentTab)
}
return view
}
my tabs were not scrolling horrizontaly. The last Title ("Organizations") has just wrapped itself (it was not fitting on screen). After adding
tabHost.tabWidget.getChildAt(i).findViewById<TextView>(android.R.id.title).setSingleLine(true)
for each of the tabs, organization TITLE started scrolling inside its tab. What am I doing wrong ?