我正在开发一个安卓应用程序,带有Tabs (FragmentTabHost)。我有一个有6个标签的FragmentActivity。此时,选项卡的名称显示为进行行跳转。我希望所有的标签,以适应屏幕的宽度,而不必做一个水平滚动视图。如何才能以良好的可视化效果显示选项卡名称。我如何才能做到这一点?
发布于 2017-06-24 00:43:28
我可以在不滚动的情况下让标签进入:
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).setPadding(0, 0, 0, 0);
mTabHost.getTabWidget().getChildAt(i).setMinimumWidth(10);
}发布于 2017-06-24 00:14:05
尝试这样更改您的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>然后在添加选项卡后在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.setHorizontalScrollBarEnabled(false);
https://stackoverflow.com/questions/44725632
复制相似问题