【Android】FragmentTabHost实现问题记录
来源:互联网 发布:汽车故障诊断软件下载 编辑:程序博客网 时间:2024/05/24 05:20
先有博文:
Android常用控件之FragmentTabHost的使用
文中有提及布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 这个布局决定了标签在上面还是在下面显示 --> <FrameLayout android:id="@+id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" /> <android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"/> </android.support.v4.app.FragmentTabHost> </LinearLayout>
在java文件中:
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
然而在实际应用的时候发现,按照博文中所写,AS(studio)会报错:
Your content must have a TabHost whose id attribute is ‘android.R.id.tabcontent’
按照提示,将FrameLayout 子布局移动到Fragment TabHost之内,并将其id更改为
android:id="@android:id/tabcontent"
将java文件中的引用改为:
mTabHost.setup(this.getApplication(), getSupportFragmentManager(), android.R.id.tabcontent);
可以通过编译,但是FragmentTabHost的内容和标签效果还未达到我们想要的效果,进过反复实验,发现需要在布局文件中做文章:
<android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" /> </LinearLayout> </android.support.v4.app.FragmentTabHost>
这样的效果是标签在下,Fragment内容在上。
详细代码示例:(其中的回答)
Android: FargmentTabHost - No tab content FrameLayout found for id xxx
0 0
- 【Android】FragmentTabHost实现问题记录
- Android Fragment FragmentTabHost问题
- Android FragmentTabhost实现选项卡
- Android底部菜单-FragmentTabHost实现
- Android两级导航菜单栏的实现--FragmentTabHost嵌套FragmentTabHost
- Android FragmentTabHost嵌套(ViewPager+Fragment)问题
- Android重写FragmentTabHost来实现状态保存
- 【Android】底部菜单栏--Fragment+FragmentTabHost实现
- 【Android】 FragmentTabHost+Fragment实现多标签页
- #Android笔记#fragment+fragmentTabHost实现底部菜单栏
- 【Android】FragmentTabHost实现底部Tab菜单选项
- 【Android UI】FragmentTabHost 实现底部菜单
- android上FragmentTabHost实现自定义Tab Indicator
- Android FragmentTabHost实现底部tab切换
- Android重写FragmentTabHost来实现状态保存
- Android重写FragmentTabHost来实现状态保存
- Android中使用FragmentTabHost实现底部导航
- Android (FragmentTabHost+RadioGroup)实现底部bar
- Oracle日期查询
- js 有框架页面跳转(target)三种情况下的应用(转载)
- 虚拟机软件VMware Workstation Pro的安装与使用
- “假作真时真亦假”:分类器设计中几个常见的评价指标
- PLSQL导入/导出数据方法
- 【Android】FragmentTabHost实现问题记录
- OS X下使用vagrant安装ubuntu环境
- ubuntu安装Sublime Text3
- poj 1061青蛙的约会 || hdu 2669 Romantic 扩展欧几里得算法
- 关于IOS平台APP审核加速
- Titan漫谈(一)
- VolGroup-lv_home 100%,扩容linux系统/目录容量 CentOS下调整home和根分区大小【最简单版】
- python locals 与 globals 之间有另外一个重要的区别
- iOS开发之删除过期Provisioning Profiles方法