禁用滚动视图内滚动列表视图

时间:2017-05-17 06:42:08

标签: android listview android-recyclerview scrollview

我在scrollview中实现两个listview时遇到问题。我有活动,我有scrollview。 这是我想要的形象

layout design

actually design

我想制作包含两个列表视图的发票,一个用于项目,一个用于跟踪数据。我能够动态制作listview高度并禁用其click事件。但现在在listview上我无法点击或滚动屏幕。 所有组件都在scrollview中。但是当我触摸列表视图时,我无法滚动滚动视图。

这是我正在管理listview

高度的代码
     public static boolean setListViewHeightBasedOnItems(ListView listView) {

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {

        int numberOfItems = listAdapter.getCount();

        // Get total height of all items.
        int totalItemsHeight = 0;
        for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
            View item = listAdapter.getView(itemPos, null, listView);
            float px = 500 * (listView.getResources().getDisplayMetrics().density);
            item.measure(View.MeasureSpec.makeMeasureSpec((int)px, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            totalItemsHeight += item.getMeasuredHeight();
        }

        // Get total height of all item dividers.
        int totalDividersHeight = listView.getDividerHeight() *
                (numberOfItems - 1);
        // Get padding
        int totalPadding = listView.getPaddingTop() + listView.getPaddingBottom();

        // Set list height.
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalItemsHeight + totalDividersHeight + totalPadding;
        listView.setLayoutParams(params);
        listView.requestLayout();
        return true;

    } else {
        return false;
    }

}`

我尝试使用recyclerview并使用此属性

note_recyclerview.setNestedScrollingEnabled(false);

但我没有得到我想要的东西。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

请勿在{{1​​}}内使用ListView

当您使用多个ScrollView时,您应该使用ListView代替android.support.v4.widget.NestedScrollView来获得正确的滚动行为。

  

ScrollView就像NestedScrollView一样,但它支持充当   新旧版本均ScrollView滚动nestedparent   Android版默认情况下启用嵌套滚动。

documentation

以下是一个例子:

child

希望这会有所帮助〜

相关问题