android默认的tab选项卡是显示在界面的顶部的,不过貌似现在很多软件里都出现了像iphone那样将选项卡放在页面底部的界面。经过几次尝试,我找到了实现类似效果的一种方法。
其实思路很简单,就是在布局文件中将选项卡<TabWidget>标签写在选项内容标签<FrameLayout>标签的下面就行了
不过需要注意的一点就是<FrameLayout>标签中android:layout_weight属性要设置为“1”。否则界面会被<FrameLayout>覆盖掉。具体代码为:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <FrameLayout android:id="@android:id/tabcontent" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-在这里添加各标签页内容---></FrameLayout> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </TabHost>
再配合自定义的背景与点击效果,很容易做出类似新浪微博那种放iphone风格的选项卡。不过最近好像流行将选项卡放在侧面的布局界面(详见火种通讯录,qq通讯录),实现方法我还在研究ing,至于有什么进展就随缘吧。。