ひらい ぶらり Hi-Library

ぷろぐらみんぐについて。ときどきどうでもいいことについて。

FragmentTabHost で TabWidget をBottom に配置する

非推奨になったTabHostを使えば、普通にbottomに配置出来たのですが、FragmentTabHostは何やらバグっているらしく、配置順やgravityを変更してもbottomに配置されませんでした。

どうやら既にIsuueとして報告されているようで、参照先のコメントにあるの様にFragmentTabHost内のメソッドの一部を削除すれば期待する動作をしてくれるそうです。

http://topsy.com/code.google.com%2Fp%2Fandroid%2Fissues%2Fdetail%3Fid%3D40035

でもわざわざソース持ってきて書き換えるのは面倒だし嫌な感じがするので、これで正しいのかどうかわからないけれども、レイアウトを書き換えることで解決してみた。

TabWidgetをbottomに配置するレイアウト

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical" >
    <LinearLayout
            android:id="@+id/logo_bar2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
        <FrameLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="#222222" />
    </LinearLayout>
    <android.support.v4.app.FragmentTabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#222222">
            <TabWidget
                    android:id="@android:id/tabs"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0"/>
    </android.support.v4.app.FragmentTabHost>
</LinearLayout>

これで大体意図した通りのレイアウトになった。 TabHost内部にcontentが存在していないが動くようだ。

いいのかなぁ・・・?