对于Android自带的tabhost组件,是位于页面顶端的,若想让其位于页面底端,在这里提供两种方法。

方法一

1、tabcontent和tabs交换位置

2、设置tabcontent的属性:android:layout_weight="1"

范例

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TabHost        android:id="@android:id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentBottom="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_weight="1" >中间部分省略            </FrameLayout>            <TabWidget                android:id="@android:id/tabs"                android:layout_width="match_parent"                android:layout_height="wrap_content" >            </TabWidget>        </LinearLayout>    </TabHost></RelativeLayout>


方法二

1、tabcontent和tabs交换位置

2、将tabs放到一个relativeLayout中,然后加上如下属性:android:layout_alignParentBottom="true"

范例

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TabHost        android:id="@android:id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentLeft="true"        android:layout_alignParentBottom="true"  >        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="match_parent"            android:layout_height="match_parent" >中间部分省略        </FrameLayout>        <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>        </RelativeLayout>    </TabHost></RelativeLayout>

方法三

1、将tabcontent和tabs交换位置(tabs移动到LinearLayout标签以下) 2、在tabcontent中加入属性:android:layout_gravity="top"
3、在tabs中加入属性:android:layout_gravity="bottom"

范例

<?xml version="1.0" encoding="UTF-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <TabHost        android:id="@android:id/tabhost"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_alignParentBottom="true"        android:layout_alignParentLeft="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>        <TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="bottom" ></TabWidget>            </TabHost></RelativeLayout>


效果图

【Android】设置tabhost位于底部的三种方法_第1张图片

更多相关文章

  1. Android 属性动画原理与DataBinding
  2. Android AIDL机制范例解析
  3. Android:TextView属性大全
  4. Mars Android视频学习笔记——01_16_SQLite使用方法
  5. 使用shape来定义控件的一些显示属性
  6. Android 总结:进阶之路(资源与方法)
  7. Android各类属性记录详解,如Edittext

随机推荐

  1. Android自定义action与permission
  2. ViewFlipper左右拨动模版,包含Listview,Scr
  3. Android(安卓)跳转应用权限设置页面 适配
  4. Android(安卓)在webview中设置代理
  5. Android(安卓)Unity Plugin 开发指南(转
  6. react-native目录分析
  7. Android_adb shell am/pm使用
  8. android Textview设置单行显示,多余的显示
  9. 给APK文件签名
  10. okhttp源码分析