0

私はAndroidのレイアウトを持っています。のようなリスナーを設定しましたlist.setOnItemClickListener。すべてがうまくいくようです。

以下の行で:

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

android:layout_heightからに変更wrap_contentするとfill_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

ScrollView は、画面に表示できる ListView 内の使用可能なすべてのスペースを占めており、基本的にそれを覆っています。

ListView は独自の垂直スクロールを処理するため、ListView で ScrollView を使用しないでください。最も重要なことは、これを行うと、大きなリストを処理するための ListView の重要な最適化がすべて無効になります。これは、ListView がアイテムのリスト全体を効果的に表示して、ScrollView によって提供される無限のコンテナーを埋めるためです。-- http://developer.android.com/reference/android/widget/ScrollView.htmlより

于 2015-02-11T11:58:39.987 に答える
0

fill_parentMATCH_PARENT( API レベル 8 以降では廃止され、名前が変更されました)

ウィジェットのレイアウトを fill_parent に設定すると、ウィジェットが配置されているレイアウト要素内で使用可能なスペースをすべて占有するように強制的に拡張されます。これは、Windows フォーム コントロールのドックスタイルを に設定することとほぼ同じですFill

最上位のレイアウトまたはコントロールを fill_parent に設定すると、強制的に画面全体が占有されます。

wrap_content

Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.

There's some details in the Android code documentation here.

于 2015-02-11T11:47:28.840 に答える