Android TabWidget底部显示效果
作者:炉火纯青 时间:2022-08-05 10:54:40
TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android: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" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
这样TabWidget显示在顶部,如果想把TabWidget放到底部有三种方式。
方式一:将TabHost中默认的LinearLayout换成RelativeLayout,并给TabWidget添加Android:layout_alignParentBottom="true"
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<RelativeLayout
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">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
</TabHost>
方式二:
1、将LinearLayout中TabWidget和FrameLayout交换位置
2、设置FrameLayout的属性:android:layout_weight="1" android:layout_height="0dp"
<TabHost xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android" rel="external nofollow" >http://schemas.android.com/apk/res/android</a>"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" ></p><p> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</TabWidget>
</LinearLayout>
</TabHost>
方式三:
1、将TabWidget移动到LinearLayout标签以下
2、在FrameLayout中加入属性:android:layout_gravity="top"
3、在TabWidget中加入属性:android:layout_gravity="bottom"
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top" >
</FrameLayout>
</LinearLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
</TabWidget>
</TabHost>
以上三种方式在Android4.2下测试通过。
标签:Android,TabWidget,底部显示
0
投稿
猜你喜欢
Java求解二叉树的最近公共祖先实例代码
2023-09-14 18:24:56
C# this关键字的四种用法
2022-10-06 07:09:22
RxJava+Retrofit实现网络请求封装的方法
2023-08-13 19:39:13
基于Spring Boot不同的环境使用不同的配置方法
2022-11-06 13:21:20
零基础写Java知乎爬虫之准备工作
2022-10-25 01:19:18
Java操作Redis详细介绍
2023-07-27 06:53:04
C#多线程之线程同步
2022-06-14 19:58:03
Git设置和取消代理的方法
2021-06-25 21:47:10
Java SSM实现前后端协议联调详解上篇
2023-09-16 20:42:22
Java实现动态获取图片验证码的示例代码
2023-07-24 22:32:05
mybatis-plus使用问题小结
2023-10-30 06:45:58
Spring Boot 应用的热部署配置方法
2022-03-26 23:36:56
C#子线程更新UI控件的方法实例总结
2022-08-31 15:40:23
C#中 Json 序列化去掉null值的方法
2022-02-02 12:13:52
java获取版本号及字节码编译版本方法示例
2023-06-22 08:44:31
Java实现AOP面向切面编程的实例教程
2023-02-20 19:32:38
java线程池详解及代码介绍
2023-09-16 07:21:57
Spring实例化bean的方式代码详解
2022-04-04 08:46:09
深入理解Spring AOP
2023-02-09 15:14:40
详解Java发送HTTP请求
2022-01-09 14:53:57