zoukankan      html  css  js  c++  java
  • Android TabWidget底部显示

    TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下:

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     android:id="@android:id/tabhost"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent" >  
    5.   
    6.     <LinearLayout  
    7.         android:layout_width="match_parent"  
    8.         android:layout_height="match_parent"  
    9.         android:orientation="vertical" >  
    10.   
    11.         <TabWidget  
    12.             android:id="@android:id/tabs"  
    13.             android:layout_width="match_parent"  
    14.             android:layout_height="wrap_content" >  
    15.         </TabWidget>  
    16.   
    17.         <FrameLayout  
    18.             android:id="@android:id/tabcontent"  
    19.             android:layout_width="match_parent"  
    20.             android:layout_height="match_parent" >  
    21.         </FrameLayout>  
    22.     </LinearLayout>  
    23. </TabHost>  

    这样TabWidget显示在顶部,如果想把TabWidget放到底部有三种方式。

    方式一:将TabHost中默认的LinearLayout换成RelativeLayout,并给TabWidget添加Android:layout_alignParentBottom="true"

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     android:id="@+id/tabhost"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:layout_alignParentLeft="true"  
    6.     android:layout_alignParentTop="true" >  
    7.   <RelativeLayout  
    8.         android:layout_width="match_parent"  
    9.         android:layout_height="match_parent">  
    10.   
    11.         <TabWidget  
    12.             android:id="@android:id/tabs"  
    13.             android:layout_width="match_parent"  
    14.             android:layout_height="wrap_content"   
    15.             android:layout_alignParentBottom="true">  
    16.         </TabWidget>  
    17.           
    18.         <FrameLayout  
    19.             android:id="@android:id/tabcontent"  
    20.             android:layout_width="match_parent"  
    21.             android:layout_height="match_parent" >  
    22.         </FrameLayout>  
    23.     </RelativeLayout>  
    24. </TabHost>  

    方式二:1、将LinearLayout中TabWidget和FrameLayout交换位置
                  2、设置FrameLayout的属性:android:layout_weight="1" android:layout_height="0dp"

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <p><TabHost xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"  
    2.     android:id="@+id/tabhost"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:layout_alignParentLeft="true"  
    6.     android:layout_alignParentTop="true" ></p><p>   <LinearLayout  
    7.         android:layout_width="match_parent"  
    8.         android:layout_height="match_parent"  
    9.         android:orientation="vertical" >  
    10.    
    11.         <FrameLayout  
    12.             android:id="@android:id/tabcontent"  
    13.             android:layout_width="match_parent"  
    14.             android:layout_height="0dp"  
    15.             android:layout_weight="1" >  
    16.         </FrameLayout>  
    17.           
    18.         <TabWidget  
    19.             android:id="@android:id/tabs"  
    20.             android:layout_width="match_parent"  
    21.             android:layout_height="wrap_content"   
    22.             android:layout_alignParentBottom="true">  
    23.         </TabWidget>  
    24.     </LinearLayout>  
    25. </TabHost></p>  

    方式三:1、将TabWidget移动到LinearLayout标签以下
                  2、在FrameLayout中加入属性:android:layout_gravity="top"
                  3、在TabWidget中加入属性:android:layout_gravity="bottom"

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     android:id="@+id/tabhost"  
    3.     android:layout_width="match_parent"  
    4.     android:layout_height="match_parent"  
    5.     android:layout_alignParentLeft="true"  
    6.     android:layout_alignParentTop="true" >  
    7.   
    8.    <LinearLayout  
    9.         android:layout_width="match_parent"  
    10.         android:layout_height="match_parent"  
    11.         android:orientation="vertical" >  
    12.    
    13.         <FrameLayout  
    14.             android:id="@android:id/tabcontent"  
    15.             android:layout_width="match_parent"  
    16.             android:layout_height="match_parent"  
    17.             android:layout_gravity="top" >  
    18.         </FrameLayout>  
    19.     </LinearLayout>  
    20.     <TabWidget  
    21.         android:id="@android:id/tabs"  
    22.         android:layout_width="match_parent"  
    23.         android:layout_height="wrap_content"   
    24.         android:layout_gravity="bottom">  
    25.     </TabWidget>  
    26. </TabHost>  

    以上三种方式在Android4.2下测试通过。

  • 相关阅读:
    相册 垂直居中; 水平居中. 1)宽度 大于高度, 宽度 100%; 2) 高度 大于 宽度 , 高度100%; getimagesize , list --->line-height , text-align, vertical-align, max-height, max-width
    PHPexcel 导入import 数据到 mysql: mysql 查询数据是否存在, 如果存在返回id, 不存在, 插入返回id. 2) mysql_query , mysql_connect, mysql_select_db, mysql_error, mysql_num_rows,mysql_close
    css 利用border 绘制三角形. triangle
    css 1) calc() 函数的使用. 2)box-sizing:border-box
    css 实现省略号. text-overflow: ellipsis; 同时设置四个属性才可以.
    table 表头固定 thead固定. 1) 使用jquery.freezeheader.js
    MapReduce的Shuffle机制
    MapReduce的ReduceTask执行机制
    MapReduce的MapTask执行机制
    MapReduce逻辑切片规则
  • 原文地址:https://www.cnblogs.com/pangguoming/p/6164827.html
Copyright © 2011-2022 走看看