如何将 FragmentTabhost 放在底部

2023-12-22

我想把 tabwidget 像 iPhone App 一样放在底部。 我知道这个布局违反了 Google 用户界面指南,但我需要。

所以,我在 Stackoverflow 上读过很多类似的帖子。 但每个帖子都不起作用。

我想使用 FragmentTabhost,而不使用外部库(例如:ActionBarsherlock

这是我的代码

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_above="@android:id/tabs" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@android:id/tabs" />

    <TabWidget
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" />
</RelativeLayout>

活动代码如下

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top);

    //set up FragmentTabhost
    FragmentTabHost host = (FragmentTabHost)findViewById(R.id.tabhost);
    host.setup(this,getSupportFragmentManager(),R.id.content);

    //add tabspec
    TabSpec tabSpec1 = host.newTabSpec("tab1");
    Button btn1 = new Button(this);
    btn1.setBackgroundResource(R.drawable.icon1);
    tabSpec1.setIndicator(btn1);
    Bundle bundle1 = new Bundle();
    bundle1.putString("name", "tab1");
    host.addTab(tabSpec1,SampleFragment.class,bundle1);


    TabSpec tabSpec2 = host.newTabSpec("tab2");
    Button btn2 = new Button(this);
    btn2.setBackgroundResource(R.drawable.icon2);
    tabSpec2.setIndicator(btn2);
    Bundle bundle2 = new Bundle();
    bundle2.putString("name", "tab2");
    host.addTab(tabSpec2,SampleFragment1.class,bundle2);

}

所以我尝试了另一种这样的布局

<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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" >

    <FrameLayout
        android:id="@+id/tabcontent"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0" />

    <TabWidget
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

请帮我,


Note最后我解决了这个问题。 这是SupportPackage的bug......

尝试这个

http://code.google.com/p/android/issues/detail?id=40035 http://code.google.com/p/android/issues/detail?id=40035


试试这个:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TabWidget
    android:id="@android:id/tab"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

<FrameLayout
    android:id="@android:id/content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 FragmentTabhost 放在底部 的相关文章

随机推荐

  • 有没有办法并行运行 C++ 单元测试?

    我使用 Boost Test 已经很长时间了 但最终我的测试运行得太慢了 由于每个测试都是高度并行的 我希望它们与我的所有核心同时运行 有没有办法使用 Boost 测试库来做到这一点 我没有找到任何解决方案 我试图了解如何编写自定义测试运行
  • Symfony 3 - 性能分析

    是否可以获得比下图更多 更深入的关于 Symfony 速度 慢度的数据 正如你所看到的 它说 控制器 进程大约需要 8 秒 在开发模式下 但我想了解更多关于它的信息 Symfony 在这 8 秒内实际上做了什么 显然 屏幕上的表单有点重 渲
  • 旋转时调整 iPhone 上的视图大小

    我有一个有很多视图的应用程序 我希望只有几个视图能够在设备旋转时旋转为横向 我发现我无法使用 BOOL shouldAutorotateToInterfaceOrientation因为这会旋转我的应用程序中的每个视图 我在 Stack Ov
  • 如何在离线 Debian 机器上安装 R 软件包?

    我有一个 Debian 虚拟机 但未连接到互联网 然而 我仍然可以从有互联网连接的本地计算机上 scp 任何文件 为了提供一些背景信息 我尝试在虚拟机上托管一个闪亮的应用程序 我仍然可以使用 apt get 命令安装旧版本的 R 3 1 1
  • 如何在 pub extern "C" fn 中返回动态长度的向量?

    我想返回一个向量pub extern C fn 由于向量具有任意长度 我想我需要返回一个结构体 指向向量的指针 以及 向量中元素的数量 我当前的代码是 extern crate libc use self libc size t int32
  • jQuery移动列表视图延迟加载

    如何在移动 jquery listview 小部件中实现延迟加载 任何人都可以举一个使用 json 格式的静态数据绑定到 jquery mobile listview 小部件的示例吗 谢谢 有几种方法 下面两种方法效果很好 JQM 方式 很
  • django 表单在点击提交时不起作用

    我正在尝试制作一种带有性别选择的表格 用户可以选择男性或女性 我现在在 forms py 中拥有什么 class GenderForm forms Form demo DemoData objects all GENDER CHOICES
  • base.html 的 Django 全局变量

    我已经实现了一个全局变量 但我真的不知道如何访问它 我发现的例子有点令人困惑 模型 py Categorys of Post Model class Category models Model title models CharField
  • 使用带有远程 git 存储库的 capistrano 进行部署,但没有在生产服务器上运行 git

    我有一个远程 git 存储库设置 用于在我的团队中进行集中开发 但是 我们部署应用程序的生产服务器当前没有运行 git 我们想要使用 capistrano 来部署我们的应用程序 如何设置部署配方以在部署时从远程 git 存储库 拉取 换句话
  • unique_ptr堆和栈分配

    原始指针可以指向在堆栈或堆上分配的对象 堆分配示例 heap allocation int rawPtr new int 100 std cout lt lt rawPtr lt lt std endl 100 堆栈分配示例 int i 1
  • 在 PHP 中从 XML 获取属性

    我正在尝试使用以下代码从 XML 文件获取属性 xmlFile http weather aero dataserver current httpparam dataSource metars requestType retrieve fo
  • 如何以编程方式删除从故事板添加的约束?

    I have googled but not find out answer So I need to ask I have one home screen When User is logged in it will display on
  • 如何在未安装 Office 的计算机上手动安装 Office 2007 PIA?

    我看到了一些其他有关的问题 尤其 可以在没有 Office 的情况下安装 Office 2007 PIA 吗 3 https stackoverflow com questions 450674 can you install office
  • 使用“严格引用”时不能使用字符串(“1”)作为哈希引用

    我正在尝试检查哈希键是否存在 例如 use warnings use strict use feature qw say use Data Dump qw dump my h a gt 1 b gt 2 dump h if exists h
  • 检查数据帧中的值是否介于另一个数据帧中的两个值之间

    我有一个与另一个问题非常相似的问题here https stackoverflow com questions 38334845 python dataframe check if a value in a column dataframe
  • oxyplot 中的中心轴

    我想用 oxyplot 绘制如下图所示的图表 问题是我不知道如何在值 50 处绘制轴 带有值 Code var model new PlotModel Title EllipseAnnotations model Axes Add new
  • 值 0 和 1 等于 php 中的 false 和 true

    有时我们在php中使用0值或1值 而不是0和1值 我们可以在php中使用True False方法吗 布尔 TRUE 值转换为字符串 1 布尔值 FALSE 转换为 空字符串 这允许在布尔值和字符串值之间来回转换 https www php
  • 将android库发布到jcenter:gradle bintrayUpload找不到库

    我正在尝试将 Android 库发布到 jcenter 我已经关注了https github com danielemaddaluno gradle jcenter publish https github com danielemadda
  • 只有一个实例可与 IIS7.5 上的 Azure October 2012 SDK 配合使用

    我刚刚将我的 Azure 解决方案升级到 VS2012 和 2012 年 10 月版本 我有 2 个 webrole 但当我从 IIS 管理器查看时 其中只有 1 个正在工作 我确信这一点 因为我的网络角色的角色间通信请求也失败了 首先我认
  • 如何将 FragmentTabhost 放在底部

    我想把 tabwidget 像 iPhone App 一样放在底部 我知道这个布局违反了 Google 用户界面指南 但我需要 所以 我在 Stackoverflow 上读过很多类似的帖子 但每个帖子都不起作用 我想使用 FragmentT