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>

I am trying to make my list view scrollable but it has become scrollable but I am unable to find the details of the list view. Please help me for the same. Friends,I have updated the header_history file also.

4

3 回答 3

0

我只回答了一个类似的问题。在这里,我向您解释为什么它不滚动?

只需从布局中删除 ScrollView。并且,将 LinearLayout 设为父级。并且,尝试运行您的应用程序。它将滚动列表。

因为 ListView 类实现了它自己的滚动并且它只是不接收手势,因为它们都由父 ScrollView 处理,我强烈建议您以某种方式简化您的布局。例如,您可以将希望滚动到 ListView 的视图添加为页眉或页脚。

看看这个

查看我现有的答案

于 2012-09-06T09:10:15.483 回答
0

You shouldn't put a ListView inside a ScrollView because the ListView class implements its own scrolling and it just doesn't receive gestures because they all are handled by the parent ScrollView.

Make TextView Scrollable.

Just set the

android:maxLines = "AN_INTEGER"

android:scrollbars = "vertical"

properties of your TextView in your layout's xml file.

Then use:

yourTextView.setMovementMethod(new ScrollingMovementMethod())

in your code.

于 2012-09-06T09:10:59.320 回答
0

问题是您将 aListView放入了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 回答