FragmentTabHost Horizontal Scrollview + Swipe Android
Posted
技术标签:
【中文标题】FragmentTabHost Horizontal Scrollview + Swipe Android【英文标题】:FragmentTabHost Horizontal Scrollview + Swipe Android 【发布时间】:2015-06-13 06:27:17 【问题描述】:我查看了以下问题
FragmentTabHost with horizontal scroll 仍然无法在 android 中获得可滚动的水平标签。所有的标签都互相粘在一起。
我的片段的onCreateView方法
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
tabHost = (FragmentTabHost) rootView.findViewById(R.id.tabhost);
tabHost.setup(getActivity(),getFragmentManager()/* getChildFragmentManager()*/, R.layout.fragment_home);
Bundle arg1 = new Bundle();
arg1.putInt("Arg for Frag1", 1);
tabHost.addTab(tabHost.newTabSpec("Tab1").setIndicator("Latest Videos"), HomeFragmentChild1.class, arg1);
Bundle arg2 = new Bundle();
arg2.putInt("Arg for Frag2", 2);
tabHost.addTab(tabHost.newTabSpec("Tab2").setIndicator("Hot Videos"), HomeFragmentChild2.class, arg2);
Bundle arg3 = new Bundle();
arg3.putInt("Arg for Frag2", 3);
tabHost.addTab(tabHost.newTabSpec("Tab3").setIndicator("My Videos"), HomeFragmentChild2.class, arg3);
Bundle arg4 = new Bundle();
arg4.putInt("Arg for Frag2", 4);
tabHost.addTab(tabHost.newTabSpec("Tab4").setIndicator("Videos"), HomeFragmentChild2.class, arg4);
Bundle arg5 = new Bundle();
arg5.putInt("Arg for Frag2", 5);
tabHost.addTab(tabHost.newTabSpec("Tab5").setIndicator("Sample Videos"), HomeFragmentChild2.class, arg5);
TabWidget tw = (TabWidget) rootView.findViewById(R.id.tabs);
LinearLayout ll = (LinearLayout) tw.getParent();
HorizontalScrollView hs = new HorizontalScrollView(this.getActivity());
hs.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
ll.addView(hs, 0);
ll.removeView(tw);
hs.addView(tw);
hs.setHorizontalScrollBarEnabled(false);
return tabHost;
XML:
<android.support.v13.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tabhost"
android:layout_
android:layout_ >
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical" >
<TabWidget
android:id="@+id/tabs"
android:layout_a
android:layout_
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_
android:layout_
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_
android:layout_
android:layout_weight="1" />
</LinearLayout>
</android.support.v13.app.FragmentTabHost>
另外,是否有可能实现一种滑动和更改标签的方法? 我最后可能的错误?会有很大帮助的!谢谢!
【问题讨论】:
将LinearLayout放入HorizontalScrollView? 不,没有帮助:( 【参考方案1】:使用 ViewPager 将是一个解决方案。
请查看此链接:Using ViewPager for Screen Slide
另见:Creating Swipe Views with Tabs
【讨论】:
以上是关于FragmentTabHost Horizontal Scrollview + Swipe Android的主要内容,如果未能解决你的问题,请参考以下文章
在 OpenStack Horizon 中保持更长时间的身份验证