android4.0 FragmentTabHost tabs在底部 仿qq界面
2016-05-04 12:13
337 查看
首先吐槽下官网, http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html ,这里居然没给出xml的配置,导致一直弄了很久。而百度搜索到的大部分都是这个配置,不只是否是版本升级的原因,我按照这个配置,运行就会报错:java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
各种尝试,最后发现只有下面这个代码能运行,但是tabs是在顶部的
最后只好谷歌了,发现了国外的大神的一个配置,就是FragmentTabHost里面什么都没放置。下面是我自己写的配置,
各种尝试,最后发现只有下面这个代码能运行,但是tabs是在顶部的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <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"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" /> </android.support.v4.app.FragmentTabHost> </LinearLayout>
最后只好谷歌了,发现了国外的大神的一个配置,就是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" > <!-- 把FragmentLayout放在FragmentTabHost上面,这样tabs就在底部了,注意,id要自己添加了 android:id="@+id/realtabcontent" --> <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="150px" > </android.support.v4.app.FragmentTabHost> </LinearLayout>
这个配置运行成功
相关文章推荐
- Android官方开发文档Training系列课程中文版:打印内容之自定义文档打印
- Android版本和 sdk版本(即API版本)的区别
- Android之SQLite数据库使用
- android shape的使用详解以及常用效果(渐变色、分割线、边框、半透明阴影效果等)
- android studio SDK下载(国内镜像)
- android电池充电以及电量检测驱动分析
- Material Design之FloatingActionBar
- android打包so文件到apk
- Android中LayoutParams的用法
- Android Vitamio 直播视频播放功能的实现
- android音乐播放器(改进版)
- 转:android surface简单使用Demo
- Material Design之SwipeRefreshLayout
- Android:onNewIntent()触发机制及注意事项
- AndroidStudio gradle配置
- Android 调用百度识图工具
- android自定义控件-瀑布流
- Android文件的读写详解
- Android中Parcel的分析以及使用
- Material Design之TextInputLayout