在 TabHost 中为 LinearLayout 设置match_parent大小 (Android)



我不明白,为什么ID为"map_tab"(第一个选项卡)的LinearLayout实际上没有高度"match_parent"?我有一个带有TabHost:的XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="#ffff"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tabHost_main"
    android:layout_gravity="center_horizontal">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <!--Вкладка №1 - карта-->
            <LinearLayout
                android:id="@+id/map_tab"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <!--Карта-->
                <HorizontalScrollView
                    android:layout_weight="1"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent">
                    <ScrollView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <ImageView
                            android:id="@+id/map_img"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:scaleType="centerInside"/>
                    </ScrollView>
                </HorizontalScrollView>
                <TextView
                    android:id="@+id/sector_advert_text"
                    android:background="#ddffaa"
                    android:layout_gravity="bottom"
                    android:gravity="bottom"
                    android:layout_width="match_parent"
                    android:layout_height="50dp" />
                </LinearLayout>
            <!--Вкладка №2 - акции-->
            <LinearLayout
                android:id="@+id/stock_tab"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <Button
                    android:text="2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>
            <!--Вкладка №3 - Маршрут -->
            <LinearLayout
                android:id="@+id/route_tab"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <Button
                    android:text="3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>
</LinearLayout>

屏幕截图

我已经尝试将高度设置为"fill_rent"。它看起来总是像"包装"。例如,如果我将"map_tab"的高度设置为50dp,它也不会正常!第二个和第三个选项卡也有这个问题。如何使选项卡的内容高度为"match_parent"?

我解决了这个问题!只需更改:

<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabHost_main"
android:layout_gravity="center_horizontal">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

上:

<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabHost_main"
android:layout_gravity="center_horizontal">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

祝你好运!:)

最新更新