0

これは私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:textSize="15sp"
        android:textStyle="bold"
        android:textColor="@android:color/holo_blue_dark"
        android:text="@string/section_1" />

    <ListView
        android:id="@+id/lv_section_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:textSize="15sp"
        android:textStyle="bold"
        android:textColor="@android:color/holo_blue_dark"
        android:text="@string/section_2" />

    <ListView
        android:id="@+id/lv_section_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="false" />

</LinearLayout>

問題は、最初のセクションに多くの項目があり、画面全体を占める場合、スクロールして2番目のセクションを表示できないことです。ListViewクイック検索で、内では使用できないことがわかりScollViewました。

LinearLayout追加できるすべてのセクションを表示できるように、このスクロール可能のままにする方法はありますか?iOS UITableViewに似たもの、いくつかのセクションとヘッダーが必要です。

前もって感謝します。

4

2 に答える 2

1

わかりました、複数のセクションを持つリストを作成するだけで、私の問題を解決するためにできることは非常に簡単でした:

1 つだけ残しListViewて、クラスを作成しましたCustomAdapter。そして、さまざまなタイプのアイテムを追加しました:

ArrayList<HashMap<String, String>> listItems = new ArrayList<HashMap<String, String>>();

HashMap map = new HashMap<String, String>();
map.put("type", "section");
map.put("title", "Section 1");
listItems.add(map);

map = new HashMap<String, String>();
map.put("type", "item");
map.put("title", "Item A");
map.put("detail", "Detail A");
listItems.add(map);

アダプターを my に設定しますListView

CustomAdapter adapter = new CustomAdapter(context, R.layout.result_list, listItems);
ListView lv = (ListView) view.findViewById(R.id.resultlist);
lv.setAdapter(adapter);

CustomAdapterの場合、タイプ、セクション、アイテムごとに異なるスタイルを設定しています。のアイテムを区別するために何かが欲しいだけであることに注意してくださいListView

私の解決策があまりにも醜い場合でも、この問題に対する提案を受け入れてください:)

于 2012-10-10T15:40:53.030 に答える
0

両方の ListView に layout_weight="1" と layout_height="0dp" を使用すると、画面全体が 2 つの部分に分割され、両方のセクションが表示されます。リストビューの上にヘッダーとしてTextViewを表示する必要がある場合は、上記の重みと線形レイアウトの内側に2つの線形レイアウトを取り、テキストビューとリストビューを垂直方向に配置します。

于 2012-10-09T15:31:37.820 に答える