0
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:orientation="vertical" >

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

        <RelativeLayout
            android:id="@+id/relativeLayout2"
            android:layout_width="fill_parent"
            android:layout_height="600dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" >

            <include
                android:id="@+id/include1"
                android:layout_width="fill_parent"
                android:layout_height="70dp"
                layout="@layout/header_history" >
            </include>

            <ListView
                android:id="@android:id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:cacheColorHint="#00000000"
                android:divider="@android:color/black"
                android:dividerHeight="1.0sp"
                android:textColor="#000000" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

header_history

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/button" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/button"
        android:gravity="left|center_vertical"
        android:text="   History"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:textStyle="bold" />

</RelativeLayout>

リスト ビューをスクロール可能にしようとしていますが、スクロール可能になりましたが、リスト ビューの詳細を見つけることができません。同じことを手伝ってください。友よ、header_history ファイルも更新しました。

4

3 に答える 3

0

問題は、 を に入れることListViewですScrollView。Android API によると、スクロール可能な要素を別のスクロール可能な要素に配置してはいけません。

とにかくこれが必要な場合は、メソッドをサブクラス化しListViewて上書きすることで問題を解決できますonMeasure()

編集: 次のコードを使用して、完全に展開されたリストを作成します。また、パフォーマンス上の理由により、これは大きなリストの場合は恐ろしい考えになる可能性があることに注意してください。

public class FullExpandedListView extends ListView {

    public FullExpandedListView(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int a, int b) {
        super.onMeasure(a, b);

        setListViewHeightBasedOnChildren();
    }

    private void setListViewHeightBasedOnChildren() {

        SwfListAdapter listAdapter = (SwfListAdapter) getAdapter();

        if (listAdapter == null) {

            return;
        }

        int totalHeight = 0;
        int desiredWidth = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST);

        for (int i = 0; i < listAdapter.getCount(); i++) {

            View listItem = listAdapter.getView(i, null, listControl);
            listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listControl.getLayoutParams();
        params.height = totalHeight + (listControl.getDividerHeight() * (listAdapter.getCount() - 1));
        setLayoutParams(params);
    }
}
于 2012-09-06T09:15:08.740 に答える
0

ListView クラスは独自のスクロールを実装し、ジェスチャーはすべて親 ScrollView によって処理されるため、ジェスチャーを受け取らないため、ListView を ScrollView 内に配置しないでください。

TextView をスクロール可能にします。

設定するだけ

android:maxLines = "AN_INTEGER"

android:scrollbars = "vertical"

レイアウトの xml ファイル内の TextView のプロパティ。

次に使用します。

yourTextView.setMovementMethod(new ScrollingMovementMethod())

あなたのコードで。

于 2012-09-06T09:10:59.320 に答える