Android TabWidget底部显示
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"
- <p><TabHost xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android">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></p>
方式三: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底部显示的更多相关文章
- android BottomNavigationView 底部显示3个以上的item
你现在可以用app:labelVisibilityMode="[labeled, unlabeled, selected, auto] labeled 所有的标签都是可见的. unlabel ...
- Android应用底部导航栏(选项卡)实例
现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其 ...
- Android自定义底部带有动画的Dialog
Android自定义底部带有动画的Dialog 效果图 先看效果图,是不是你想要的呢 自定义Dialog package --.view; import android.app.Dialog; imp ...
- dialog自适应大小、固定大小、底部显示
创建一个从底部显示的对话框 if (dialog == null) { dialog = new Dialog(context, R.style.theme_from_bottom); View vi ...
- Android动态控制状态栏显示和隐藏
记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...
- Android 全屏显示
Android全屏显示: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInst ...
- Android之垂直显示TextView
Android之垂直显示TextView 1因为界面需求原因,需要TextView垂直显示,话不多说,看代码,我也是搜的例子,在此感谢写这个例子的大神,在此做个笔记和分享给大家 2.用到了自定义控件的 ...
- Android 修改底部导航栏navigationbar的颜色
Android 修改底部导航栏navigationbar的颜色 getWindow().setNavigationBarColor(Color.BLUE); //写法一 getWindow().set ...
- Android在ListView显示图片(重复混乱闪烁问题)
Android在ListView显示图片(重复混乱闪烁问题) 1.原因分析 ListView item缓存机制: 为了使得性能更优,ListView会缓存行item(某行相应的View). ListV ...
随机推荐
- 在jasp页面循环显示
<% int h=3;//行数 int l=3;//列数 %> <table> <% for(int i=0;i<h;i++){ %> <tr> ...
- C语言 05 数组
数组作为函数参数,可以省略元素个数. 数组作为函数参数,传递是整个数组的地址,修改函数形参数组的值,会影响到外面的 实参数组. 基本数据类型作为函数参数,传递是数值.
- mysql 启动不了了
在做测试的工程中,发现mysql启动失败,报错信息如下: --03T08::.969163Z mysqld_safe mysqld from pid file /var/data/my3306/run ...
- angular-笔记
ng-model 指令ng-model 指令 绑定 HTML 元素 到应用程序数据.ng-model 指令也可以:为应用程序数据提供类型验证(number.email.required).为应用程序数 ...
- Promise对象
1.Promise思想:每一个异步任务立刻返回一个Promise对象,由于是立刻返回,所以可以采用同步操作的流程.这个Promises对象有一个then方法,允许指定回调函数,在异步任务完成后调用. ...
- 一个ubuntu phper的自我修养(workbench)
workbench从此和navicat的激活码说再见 workbench是一个免费易用功能强大的mysql图形化管理软件,navicat上用到的功能,workbench上都能找到. 一.workben ...
- 为现有图像处理程序添加读写exif的功能
为现有图像处理程序添加读取exif的功能 exif是图片的重要参数,在使用过程中很关键的一点是exif的数据能够和图片一起存在.exif的相关功能在操作系统中就集成了,在csharp中也似乎有了实现. ...
- DllImport attribute的总结
C#有没有方法可以直接都用已经存在的功能(比如Windows中的一些功能,C++中已经编写好的一些方法),而不需要重新编写代码? 答案是肯定,就是通过接下来要说的 DllImport . DllImp ...
- 2017年1月4日 16:16:24开始学习Linux——好像回到上次发随笔的时间。
auto为C语言局部变量的默认属性 static指明变量的静态属性,也具有作用域限定符的意义 static修饰的全局变量作用域只是生命的文件中,修饰的函数作用域只是声明的文件中 register指明将 ...
- 后缀数组:倍增法和DC3的简单理解
一些定义:设字符串S的长度为n,S[0~n-1]. 子串:设0<=i<=j<=n-1,那么由S的第i到第j个字符组成的串为它的子串S[i,j]. 后缀:设0<=i<=n- ...