1

リストビューも含むスクロール可能なリストが必要です。私はどこでも調査を行いましたが、まだ解決策はありません:(以下のコードに従って、ScrollViewを追加すると、リストビューの高さが小さくなります(単一行)。ListViewの高さを(コンテンツに基づいて)動的にし、完全なものにしたいページスクロール可能.どうすればこれを達成できますか?または動的な線形/相対リストUIを作成する方法はありますか?提案してください.

XML コード:

<?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="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="@dimen/activity_horizontal_margin"
    android:orientation="vertical" >

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin">

        <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/kollege_name"
        android:width="170dp" />

        <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:gravity="right"
        android:text="@string/grade_value"
        android:width="120dp" />

        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:text="@string/code_value" />
        </RelativeLayout>

        <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@android:color/darker_gray" />


        <TextView
        android:id="@+id/textView4"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/your_fit"
        android:textSize="12sp" />

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

        <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@android:color/darker_gray" />

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin" >

        <TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tuition"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"

            android:text="@string/tuition_value" />

        </RelativeLayout>


        <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@android:color/darker_gray" />

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin" >

        <TextView
        android:id="@+id/textView12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/placements"
        android:textSize="12sp" />

        <TextView
        android:id="@+id/textView13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView12"
        android:text="@string/EXTC"
        android:layout_marginTop="3dp" />

        <TextView
        android:id="@+id/textView14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView13"
        android:text="@string/IT"
        android:layout_marginTop="3dp" />

        <TextView
        android:id="@+id/textView15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView14"
        android:text="@string/COMP"
        android:layout_marginTop="3dp" />

        <TextView
        android:id="@+id/textView16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView15"
        android:text="@string/MECH"
        android:layout_marginTop="3dp" />

        <TextView
        android:id="@+id/textView17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView16"
        android:text="@string/INST"
        android:layout_marginTop="3dp" />
        </RelativeLayout>

        <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@android:color/darker_gray" />


        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin" >

        <TextView
        android:id="@+id/textView18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/placements"
        android:textSize="12sp" />

        <TextView
        android:id="@+id/textView19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView18"
        android:text="@string/EXTC"
        android:layout_marginTop="3dp" />

        <TextView
        android:id="@+id/textView20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView19"
        android:text="@string/IT"
        android:layout_marginTop="3dp" />
        </RelativeLayout>
        </LinearLayout>

        </ScrollView>

</LinearLayout>
4

3 に答える 3

11

ListView アダプター内で異なるビュー タイプを設定するか、ListView フッターとヘッダーを使用することをお勧めします。

また、このメソッドを使用して、ScrollView の ListView で直面している問題を修正することもできます

public static void updateListViewHeight(ListView myListView) {
     ListAdapter myListAdapter = myListView.getAdapter();
     if (myListAdapter == null) {            
              return;
     }
    //get listview height
    int totalHeight = 0;
    int adapterCount = myListAdapter.getCount()
    for (int size = 0; size < adapterCount ; size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    //Change Height of ListView 
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight + (myListView.getDividerHeight() * (adapterCount - 1));
    myListView.setLayoutParams(params);
}
于 2013-09-18T04:09:19.043 に答える
2

リストビューをスクロールビュー内に配置しないでください。リストビューをスクロールビューの外に置くか、他のビューをヘッダーとフッターとしてリストビューに追加します。

ドキュメントからの引用

ScrollViewListViewListViewは独自の垂直スクロールを処理するため、 aと一緒に使用しないでください。最も重要なことは、これを行うと、大きなリストを処理するための の重要な最適化がすべて無効になります。これは、 が提供する無限のコンテナを満たすために、アイテムのリスト全体をListView効果的に表示するように強制するためです。ListViewScrollView

ビューをヘッダーおよびフッターとしてリストビューに追加できます。ヘッダーとフッターがスクロールします。

Android でのスクロールなしの ListView

于 2013-09-18T03:41:08.850 に答える
2

スクロールビューでリストビューを使用しないでください.それぞれに独自のスクロールがあるため.私もこの問題に苦しんでいます.レイアウトに両方を設定したい場合は、リストビューの重みを設定するだけです.

于 2013-09-18T03:45:49.963 に答える