我正在尝试将HorizontalScrollView添加到FragmentTabHost。我遵循了FragmentTabHost with horizontal scroll的“ Lor Giver”答案 但它对我不起作用。 像这样实现xml之后:
<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>
并像这样设置它:
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
}
我的标签没有水平滚动。最后一个标题(“组织”)刚刚包装好自己(屏幕上不合适)。 添加
之后tabHost.tabWidget.getChildAt(i).findViewById<TextView>(android.R.id.title).setSingleLine(true)
对于每个选项卡,组织TITLE开始在其选项卡内滚动。我在做什么错了?