对项目做一些简单的框架搭建仍然是用的以前自己写的布局框架。在使用AndroidStudio的时候发现
android.support.v4.app.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"
android:background="@drawable/bottom_bg" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
之后在网上找到了一篇博客,问题解决:http://blog.csdn.net/deng0zhaotai/article/details/48295285
这边文章真心难找,在百度的搜索方式不一样,一般是搜索R.id.tabcontent的错误日志,这里是
“fragmenttabhost在新版v4包中”才能搜到这篇文章,我一开始也没想到是新V4包的版本问题,
因为androidstudio是最新下载的,创建项目的时候V4包自动使用最新的,所以我以前使用的V4
包是没这个bug的,而新版中暴露了出来,尝试使用了最新的android.support.design.widget.TabLayout,发现有Bug,当标签栏在底部时,系统会先加载内容页,
而不加载标签页,网上说开一个线程来手动加载标签页,我试了一下还是不行。。。如果有人成功了
麻烦告诉我方法,非常感谢!
这里对上述引用的博客再做一些补充。
博客所说的最后一个代码片段描述如下:
<?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"
android:background="@drawable/bottom_bg" >
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
遮挡的问题,在
<android.support.v4.app.FragmentTabHost ><<android.support.v4.app.FragmentTabHost />
这段代码中少了TabWidget这个控件,添加进去之后,按照其所说自定义了framelayout的id
代码中进行相应的更改,可仍然是不行的,提示“R.id.content XXXXXX”错误,我这里直接用的
倒数第二个代码段:
<?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" >
<android.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:background="#B0C4DE"
android:orientation="horizontal"
android:showDividers="middle" />
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
关于这个布局会导致覆盖掉TabWidget控件的问题,我这里在TabWidget所包含既一个标签布局中,
使用了warpcontent,然后将TabWidget控件修改:android:layout_height=”40dp”。一般底部标签
不会有多大,所以这里直接定义了一个比较高的dp值,一般是没什么问题的。如果有完美解决覆盖
问题的请告诉我,谢谢~