0

我有一个 Android 布局。我已经设置了一个像list.setOnItemClickListener. 一切似乎都很好。

在下面的行中:

<ScrollView android:layout_width="fill_parent"
            android:layout_height="wrap_content">

如果我android:layout_height从更改wrap_contentfill_parent它不再起作用(无法选择我列表中的项目)。

只有设置为wrap_content. 为什么会这样?

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <TabWidget android:id="@android:id/tabs"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
            />
    <FrameLayout android:id="@android:id/tabcontent"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
            >
        <ListView android:id="@+id/restaurants"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                />
        <ScrollView android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

            <TableLayout android:id="@+id/details"
                         android:layout_width="match_parent"
                         android:layout_height="wrap_content"
                         android:stretchColumns="1"
                         android:shrinkColumns="1"
                         android:paddingTop="4dip"
                    >
                <TableRow>
                    <TextView android:text="@string/name" />
                    <EditText android:id="@+id/name" />
                </TableRow>
                <TableRow>
                    <TextView android:text="@string/address" />
                    <EditText android:id="@+id/addr" />
                </TableRow>
                <TableRow>
                    <TextView android:text="Type:" />
                    <RadioGroup android:id="@+id/types">
                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/take_out"
                                     android:text="@string/takeout"
                                     android:checked="true"
                                />

                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/sit_down"
                                     android:text="@string/sitdown"
                                />
                        <RadioButton android:layout_height="wrap_content"
                                     android:layout_width="wrap_content"
                                     android:id="@+id/delivery"
                                     android:text="@string/delivery"
                                />
                    </RadioGroup>
                </TableRow>

                <TableRow>
                    <TextView android:text="@string/notes" />
                    <EditText android:id="@+id/notes" />
                </TableRow>

                <Button android:id="@+id/save"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/save"
                        />
            </TableLayout>
        </ScrollView>
    </FrameLayout>
</LinearLayout>
</TabHost>
4

2 回答 2

0

Your ScrollView is taking up all avaliable space inside your ListView that can populate on your screen, basically covering it up.

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView. --From http://developer.android.com/reference/android/widget/ScrollView.html

于 2015-02-11T11:58:39.987 回答
0

fill_parentMATCH_PARENT(在 API 级别 8 及更高版本中已弃用并重命名)

将小部件的布局设置为 fill_parent 将强制它展开以占用其所在布局元素中可用的空间。这大致相当于将 Windows 窗体控件的 dockstyle 设置为Fill.

将顶级布局或控件设置为 fill_parent 将强制它占据整个屏幕。

wrap_content

将 View 的大小设置为 wrap_content 将强制它仅扩展到足以包含它所包含的值(或子控件)的程度。对于控件——如文本框 (TextView) 或图像 (ImageView)——这将包装正在显示的文本或图像。对于布局元素,它将调整布局大小以适应作为其子元素添加的控件/布局。

此处的 Android 代码文档中有一些详细信息。

于 2015-02-11T11:47:28.840 回答