2

我正在使用 TabHost 并且在一个选项卡内,我插入了 ListView。我将所有高度设置为fill_parent。但它没有显示完整的列表,而只是其中的一部分。如何使标签内容按高度填充屏幕?

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bkg"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="7dp"
            android:layout_marginRight="7dp"
            android:layout_marginTop="7dp"
            android:background="@drawable/gradientrounded"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:src="@drawable/taxisign" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/taxiprofiletitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_weight="0.9"
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="#000000" />

                <Button
                    android:id="@+id/phonenumber"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="4dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/button"
                    android:paddingBottom="5dp"
                    android:paddingTop="5dp"
                    android:text="Button"
                    android:textColor="#ffffff" />
            </LinearLayout>

            <ProgressBar
                android:id="@+id/loadFeedbacks"
                style="?android:attr/progressBarStyleLarge"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:visibility="invisible" />
        </LinearLayout>

        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFFF0000" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:background="#FF000000"
                    android:layout_height="wrap_content" >
                    <TextView
                        android:tag="tab0"
                        android:text="Инфо"
                        android:background="@android:drawable/btn_star_big_on"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        />
                    <TextView
                        android:tag="tab1"
                        android:text="Отзывы"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        />
                    <TextView
                        android:tag="tab2"
                        android:text="Тарифы"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        />
                </TabWidget>

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1" >

                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <TextView
                            android:id="@+id/profile_info"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Info" />
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical" >

                            <TextView android:text="Добавить"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">

                            </TextView>
                            <ImageButton 
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"/>
                        </LinearLayout>
                        <ListView
                            android:id="@+id/reviewslist"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" >
                        </ListView>

                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <ListView
                            android:id="@+id/tariffslist"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1" >
                        </ListView>

                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>


    </LinearLayout>

</ScrollView>
4

4 回答 4

1

在您第一次LinearLayout更改layout_height="match_parent". 此外,fill_parent自 API 8 以来已弃用并替换为,match_parent因此您应该使用它。

于 2013-03-21T18:24:50.503 回答
1

您已经为您的 listView 高度使用了换行内容。您应该始终使用高度作为 match_parent/fill_parent。我想你的问题在这里

                    <ListView
                        android:id="@+id/reviewslist"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" >
                    </ListView>

将其更改为:

                     <ListView
                        android:id="@+id/reviewslist"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </ListView>

除此之外,这种布局似乎是无效的。不推荐在滚动视图中使用列表视图。

于 2013-03-21T18:26:58.353 回答
0

在快速查看 XML 文件时,您的 TabHost (LinearLayout) 的父级似乎是“wrap_content”,所以我不确定您是否得到了所有的父级。我确实希望有一个更好的 UI 界面来通过 Eclipse 构建视觉效果。当他们出现时,不太乐意解决这样的问题。他们可以经常出现。通常它需要一些试验和错误才能让事情看起来像我想要的那样。

于 2013-03-21T18:24:28.047 回答
0

滚动布局是不必要的,删除它,使代码工作

于 2013-03-22T13:24:22.647 回答