安卓:列表视图内滚动型视图、列表

2023-09-04 03:10:31 作者:今天也很想你

我想有一个布局,可以滚动和里面一个列表视图。 在ListView将扩大它在它有多少项的高度基地。只有滚动型外面是滚动的。 这是我的code:

I want to have a layout that can scroll and a listview inside it. The listview will expand it's height base on how many items in it. Only the ScrollView outside is scrollable. This is my code:

<ScrollView
            android:id="@+id/layout_box"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

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

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/layout_height_small"
                    android:gravity="center_vertical" >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/layout_margin_medium"
                        android:layout_marginTop="@dimen/layout_margin_medium"
                        android:gravity="center"
                        android:text="@string/list_regist_box_content"
                        android:textSize="@dimen/text_size_medium"
                        android:textStyle="bold" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="#ffffff" >

                    <ListView
                        android:id="@+id/list_registed_box"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content" >
                    </ListView>
                </RelativeLayout>

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

                    <TextView
                        android:id="@+id/btn_add_regist_box"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginTop="3dp"
                        android:gravity="center"
                        android:paddingBottom="@dimen/layout_margin_medium"
                        android:paddingTop="@dimen/layout_margin_medium"
                        android:text="@string/add_regist_box"
                        android:textColor="#0F88FF"
                        android:textSize="@dimen/text_size_medium" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_marginLeft="@dimen/layout_margin_medium"
                        android:layout_marginTop="@dimen/layout_margin_large"
                        android:gravity="center"
                        android:text="@string/amount"
                        android:textSize="@dimen/text_size_medium"
                        android:textStyle="bold" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/common_row_height"
                    android:background="@drawable/white_bg_grey_border_bottom"
                    android:gravity="center_vertical"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/list_regist_description"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="@dimen/layout_margin_medium"
                        android:layout_marginRight="@dimen/layout_width_medium"
                        android:gravity="center_vertical"
                        android:text="@string/total"
                        android:textSize="@dimen/text_size_medium" />
                </LinearLayout>
</ScrollView>

但列表视图既不是展开的,也没有滚动的。

But the listview is neither expanded nor scrollable.

请帮忙!

推荐答案

不要把里面的ListView滚动型 - 安卓clud的第一条规则:​​) 相反,你可以使用简单的LinearLayout和管理你里面的ListView项目。 或者你也可以添加页眉/页脚欣赏到ListView和使用它无需滚动型。

Don't put ListView inside ScrollView - first rule of android clud :) Instead you can use simple LinearLayout and manage you ListView items inside it. Or you can add Header/Footer Views to the ListView and using it without scrollview.