首页 新闻 赞助 找找看

tabhost始终在顶端,我想让tab页在底部,哪位高人告诉我一下要怎么改?

0
悬赏园豆:20 [已解决问题] 解决于 2012-12-24 20:25

tabhost始终在顶端,我想让tab页在底部,哪位高人告诉我一下要怎么改?

下面贴上源码和布局配置文件,请好心人帮忙看一下,谢谢了。

java文件:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        myTabhost=this.getTabHost();
        LayoutInflater.from(this).inflate(R.layout.friendbydoghome, myTabhost.getTabContentView(), true);
        myTabhost.setBackgroundColor(Color.argb(150, 22, 70, 150));
        
        myTabhost.addTab(myTabhost.newTabSpec("One").setIndicator("A",getResources().getDrawable(R.drawable.one))
                        .setContent(R.id.widget_layout_blue));
        myTabhost.addTab(myTabhost.newTabSpec("Two").setIndicator("B",getResources().getDrawable(R.drawable.two))
                        .setContent(R.id.widget_layout_green));
        myTabhost.addTab(myTabhost.newTabSpec("Three").setIndicator("C",getResources().getDrawable(R.drawable.three))
                        .setContent(R.id.widget_layout_red));

        myTabhost.setOnTabChangedListener(this);
    }

然后是两个布局文件:

第一个:main.xml 是tabhost的配置文件

<tabhost xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" >
   
    <RelativeLayout android:id="@+id/tabhost_Relative"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical" > 
        
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="50dp" />
        
         <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</tabhost>

第二个是tab页中显示的内容的xml文件

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@+id/widget_layout_blue"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView android:id="@+id/widget_layout_red"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <TextView android:id="@+id/widget_layout_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

最后是现实出来的效果:

 我想让这3个tab页放到底部,可是

问题补充:

我对tabwidget配置了置底的参数

<TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true" />

 

可是没有效果,有人知道吗?求助啊

无尘24的主页 无尘24 | 初学一级 | 园豆:24
提问于:2012-10-23 22:45
< >
分享
最佳答案
0

代码晚上贴出??代码呢 我帮你看一下

收获园豆:20
无与hebe | 菜鸟二级 |园豆:324 | 2012-12-22 09:52
其他回答(3)
0

继承自TabActivity,通过 this.getTabHost();获取到的是使用系统自带的tabhost的,而不是我layout文件中写的tabhost,也就是说我在xml文件中写的tabhost根本没有使用,所以对它的修改自然也不会生效。

修改方式:继承自Activity,通过getviewByID接口获取tabhost所在的view,强转为TanHost类型进行使用,同时要求调用setup接口。

<FrameLayout 中内容是可以被呈现的tab页指代的具体的内容。

所以,如果3个tab页呈现的内容比较复杂,且通常情况下普遍都比较复杂,那建议把<FrameLayout>中的内容放到额外的xml文件中,然后配置与该布局文件对应的activity(包括java文件和配置文件),在addTab的时候讲3个activity add进来。

代码晚上贴出

无尘24 | 园豆:24 (初学一级) | 2012-10-24 09:44
0

你把 RelativeLayout 改为LinearLayout 试下

锄田 | 园豆:217 (菜鸟二级) | 2012-12-20 14:27
0

  用  RelativeLayout 再使用属性 android:layout_above  可以把  tabwidget  放在 framlayout 下面  

 <RelativeLayout

      android:layout_width="fill_parent"

      android:layout_height="fill_parent">

   <FrameLayout

     ......................

        android:layout_above="@android:id/tabs">

    </FrameLayout>

    <TabWidget

       android:id="@android:id/tabs"

    ....

       />

  </RelativeLayout>

luoshao1228 | 园豆:202 (菜鸟二级) | 2013-05-16 16:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册