开发者

TabHost/TabWidget views not centering in parent

Have a TabHost that doesn't center the views even though I set the views layout_gravity to center_horizontal. Here is my XML, the button is all I've added to the tab1 layout so far.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"   android:layout_height="fill_parent">
    <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
        <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
        <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_pa开发者_如何学Crent" android:id="@+id/tab1">
                <Button android:layout_width="wrap_content" android:id="@+id/button1" android:layout_gravity="center_horizontal" android:text="Button" android:layout_height="wrap_content"></Button>
            </LinearLayout>
            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout>
            <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab3"></LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>


you have to set gravity at the parent!


Try setting the android:gravity attribute on the parent of the button instead.

Like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <TabHost android:id="@+id/tabhost" android:layout_width="fill_parent"   android:layout_height="fill_parent">
    <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="fill_parent" android:orientation="vertical">
    <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
    <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@android:id/tabcontent">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab1" android:gravity="center_horizontal">
            <Button android:layout_width="wrap_content" android:id="@+id/button1" android:text="Button" android:layout_height="wrap_content"></Button>
        </LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab2"></LinearLayout>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tab3"></LinearLayout>
    </FrameLayout>
    </LinearLayout>
 </TabHost></LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜