[英]Make all tabs of FragmentTabHost fit within screen
I'm developing a android app, with Tabs ( FragmentTabHost
). 我正在使用Tabs(
FragmentTabHost
)开发一个Android应用程序。 I have a FragmentActivity
with 6 tabs. 我有一个带有6个标签的
FragmentActivity
。 At the moment the name of the tab is shown doing a line jump. 此时,选项卡的名称显示为跳行。 I would like all tabs to fit in the width of the screen without having to do a horizontal scroll view.
我希望所有选项卡都适合屏幕的宽度,而不必进行水平滚动查看。 How can I show the tab names with good visualization.
如何以良好的可视化效果显示选项卡名称。 How can I achieve this?
我该如何实现?
try this change your xml layout like this 试试这个改变你的XML布局这样
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
Then in the onCreate after adding the tabs (also programmatically): 然后在添加选项卡后(也以编程方式)在onCreate中:
TabWidget tw = (TabWidget) findViewById(android.R.id.tabs);
LinearLayout ll = (LinearLayout) tw.getParent();
HorizontalScrollView hs = new HorizontalScrollView(this);
hs.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
ll.addView(hs, 0);
ll.removeView(tw);
hs.addView(tw); hs.addView(tw); hs.setHorizontalScrollBarEnabled(false);
hs.setHorizontalScrollBarEnabled(false);
I was able to make the tabs enter without scrolling with this: 我能够输入标签而无需滚动:
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).setPadding(0, 0, 0, 0);
mTabHost.getTabWidget().getChildAt(i).setMinimumWidth(10);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.