首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使FragmentTabHost的所有选项卡都适合屏幕

使FragmentTabHost的所有选项卡都适合屏幕
EN

Stack Overflow用户
提问于 2017-06-23 23:58:03
回答 2查看 46关注 0票数 0

我正在开发一个安卓应用程序,带有Tabs (FragmentTabHost)。我有一个有6个标签的FragmentActivity。此时,选项卡的名称显示为进行行跳转。我希望所有的标签,以适应屏幕的宽度,而不必做一个水平滚动视图。如何才能以良好的可视化效果显示选项卡名称。我如何才能做到这一点?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-24 00:43:28

我可以在不滚动的情况下让标签进入:

代码语言:javascript
运行
复制
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
    mTabHost.getTabWidget().getChildAt(i).setPadding(0, 0, 0, 0);
    mTabHost.getTabWidget().getChildAt(i).setMinimumWidth(10);
}
票数 0
EN

Stack Overflow用户

发布于 2017-06-24 00:14:05

尝试这样更改您的xml布局

代码语言:javascript
运行
复制
<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中(也是以编程方式):

代码语言:javascript
运行
复制
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);

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44725632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档