0

私は、いくつかのタブを持つ GUI で構成される小さなプロジェクトに取り組んできました。私はフラグメントの概念にまったく慣れていませんが、Android タブのランドスケープ内でのベスト プラクティスのようです。3 つのタブを切り替える単純なタブ アプリをコーディングすることができました。

唯一の問題は、タブを画面の下部に配置しようとしたときです。それらが一番​​下にあるとき、タブ ウィジェットはコンテナー (この場合はフレーム レイアウト) をカバーするため、何も起こらず、さまざまなタブをクリックしても画面は同じままです。

次の XML レイアウトは、適切なバージョン (タブが画面の上部にある) を表しています。

<?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="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        </LinearLayout>
    </TabHost>
</LinearLayout>

次の XML レイアウトは、タブが画面の下部にあるときに機能しないバージョンを表しています。

<?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="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <RelativeLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

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

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
             />

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
            />
        </RelativeLayout>
    </TabHost>
</LinearLayout>

私はlayourをrelativelayoutに変更し、このコマンドを追加しました: android:layout_alignParentBottom="true" をtabwidgetに追加しました。この問題をどのように分類できるかについて、別のアイデアを持っている人はいますか? 前もって感謝します。

4

2 に答える 2

2

一般に、画面の下部にあるタブを使用するのは適切ではありません ( Android デザイン ガイドラインを参照)。

あなたの解決策のために:TabWidgetビューのリストの最後に置きます。描画は線処理と断片化のため、このケースは上部の TabWidget に描画されます

于 2012-08-06T11:36:30.373 に答える