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" />
可是没有效果,有人知道吗?求助啊
代码晚上贴出??代码呢 我帮你看一下
继承自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进来。
代码晚上贴出
你把 RelativeLayout 改为LinearLayout 试下
用 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>