TabHost 置于底部 顶部的方法

对于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>  
          
        <TabWidget  
            android:id="@android:id/tabs"  
            android:layout_width="match_parent"  
            android:layout_height="wrap_content"  
            android:layout_gravity="bottom" >  
        </TabWidget>  
          
    </TabHost>  
  
</RelativeLayout>

Android 实战教程类FaceBook,欢迎学习交流!!!!

http://edu.51cto.com/course/course_id-3153.html

时间: 2024-07-31 12:23:31

TabHost 置于底部 顶部的方法的相关文章

【Android基础篇】TabHost实现底部导航栏

在App应用中,导航栏往往是用于解决功能分块的最佳控件,而底部导航栏更是导航栏中最常用的,因为它位于屏幕底部,用户操作起来会很方便. 下面介绍一下使用Android控件TabHost实现底部导航栏的方法. TabHost可以在控件库里直接拖到页面上,非常方便,但拖出来的是顶部导航栏,如下图所示: 到这里就可以开始实现底部导航栏了,我们首先转到它的XML布局代码里,然后修改成下面这样: <FrameLayout xmlns:android="http://schemas.android.co

Android ViewPager实现Tabhost选项卡底部滑块动态滑动过渡

 <Android ViewPager实现Tabhost选项卡底部滑块动态滑动过渡> 之前基于github上的第三方开源控件ViewPagerIndicator的UnderlinePageIndicator(原文链接:http://blog.csdn.net/zhangphil/article/details/44752213),自己写了一个底部带有滑块.且当ViewPager页面切换时候选项卡也随之相应切换,且滑块也随之相应动态滑动效果得控件.但写的太过于紧耦合,不利于复用,所以现在重构

CSS div水平垂直居中和div置于底部

一.水平居中 .hor_center { margin: 0 auto; } 二.水平垂直居中 .content { width: 360px; height: 240px; } .ver_hor_center { position: absolute; top: 50%; left: 50%; margin-left: -180px; /*要居中的div的宽度的一半*/ margin-top: -120px; /*要居中的div的高度的一半*/ } 三.div置于底部(footer) .bot

在div中使用css让文字底部对齐的方法

css对文字的布局上没有靠容器底部对齐的参数,不过我们可以使用position的相对和绝对定位功能轻松实现文字靠近div底部对齐,并且靠近的距离可以调节,精确到像素,在网上搜集到三段代码如下.由www.169it.com 搜集整理 代码1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <!DOCTYPE HTML PUBLIC   "-//W3C//DTD HTML 4.01 Transit

在网页静态页面里面怎么跳转底部顶部的代码

跳到网页底部html代码: 在</body>前加个<a name="bottom"></a> 在任何地方写<a href="#bottom">跳到底部</a> 就可以实现点击回到底部: 返回网页顶部代码: <a href=#top>顶部</a> 在网页静态页面里面怎么跳转底部顶部的代码

Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)

方法一 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 隐藏标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); // 隐藏状态栏 getWindow().setFlags(WindowManager.La

RecyclerView 判断滑到底/顶部的方法

判断RecyclerView到达底部的几种方法 项目中的案例 mRvChat.addOnScrollListener(new RecyclerView.OnScrollListener() { private int minLeftItemCount=10;//剩余多少条时开始加载更多 @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (recyclerView.getLayoutMa

iOS AutoLayout自动布局中级开发教程(7)-底部顶部baseLine基线对齐

如何对多个view或者Button添加底部对齐顶部对齐等等类似的对齐约束呢?最简单的方法使用 storyboard,在后续的教程中将使用代码实现. 如下图,如何为这两个或者多个视图添加 底部对齐呢? (或者顶部对齐,左对齐,右对齐,基线baseLine对齐?) 首先说明一下对齐的实质: 顶部或者底部对齐: 本质上就确定了 一个视图的y坐标 左边或者右边对齐:本质上确定了一个视图的x坐标 centerX/Y对齐:确定 x/y坐标 注意对齐的前提是要 这其中的一个的顶部(或者底部,等等)约束已经确定

Android开发--------------WebView(二)之WebView的滑动底部顶部监听,加载进度条等设置

整理一下WebView的一些常用设置,滑动监听,让跳转的页面也在WebView里显示,加载进度,获得标题等等 一,滑动监听 滑动监听的话是需要在WebView基础之上在加强一下,因为在WebView没有直接监听滑动的方法,看WebView的源码则会发现有一个 protected void onScrollChanged(int l, int t, int oldl, int oldt) : 这个方法.是受到保护的所以我们无法直接使用,所以我们写一个加强的WebView,利用接口回调. Scrol