自定义可扩展ListView在ScrollView上触发滚动

时间:2015-05-18 00:26:13

标签: android listview scrollview

我有一个自定义ExpandableScrollView(与库存无关):

public class ExpandableListView extends ListView
{
    public ExpandableListView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        expand();
    }

    public void expand() {
        ListAdapter mAdapter = getAdapter();

        int totalHeight = 0;

        for (int i = 0; i < mAdapter.getCount(); i++) {
            View mView = mAdapter.getView(i, null, this);

            mView.measure(
                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),

                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

            totalHeight += mView.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = totalHeight
                + (getDividerHeight() * (mAdapter.getCount() - 1));
        setLayoutParams(params);
        requestLayout();
    }
}

我在ScrollView中有一个这个视图的实例。问题是当布局膨胀并附加到窗口时,ScrollView会滚动到底部。

我试图弄清楚ScrollViewExpandableScrollView是否存在问题。也许我应该在另一个循环中扩展列表?

由于

0 个答案:

没有答案