如何制作第一个布局水平滚动?

时间:2016-12-30 04:12:59

标签: java android scrollview

我在3个父项布局中有2个线性布局。现在,当我在Vertical和Horizo​​ntal中滚动它们时它们是同步的。如何在第一个布局上禁用垂直滚动但两个线性布局的水平滚动仍然 SYNCHRONIZED

<ScrollView>
    <HorizontalScrollView>

        <RelativeLayout>
            <LinearLayout>  --
                             |--First layout horizontal scrollable only
            </LinearLayout> --

            <LinearLayout>  --
                             |--Second layout both scrollable
            </LinearLayout> --
        <RelativeLayout>

    <HorizontalScrollView>
<ScrollView>

以下是用于与滚动视图同步的功能,不确定它是否有帮助

public void setListViewHeightBasedOnChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null)
            return;

        int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
        int totalHeight = 0;
        View view = null;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            view = listAdapter.getView(i, view, listView);
            if (i == 0)
                view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));

            view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
            totalHeight += view.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);
    }

函数调用():

setListViewHeightBasedOnChildren(FirstLayout);

真的需要帮助!!!谢谢!

0 个答案:

没有答案