简体   繁体   English

禁用列表视图在scrollview中滚动

[英]disable listview scrolling inside scrollview

I am facing problem to implement two listview in scrollview. 我面临在滚动视图中实现两个listview的问题。 I have activity in which I have scrollview. 我有可进行滚动浏览的活动。 here is image what I want 这是我想要的图像

layout design 版图设计

actually design 实际设计

I want to make invoice which contain two listviews one for items and one for tracking data. 我要制作包含两个列表视图的发票,一个用于项目,一个用于跟踪数据。 I am able to make listview height dynamically and also disable its click event. 我能够动态地使listview高度,也可以禁用其click事件。 but now on listview I am not able to click or scroll screen. 但是现在在列表视图中,我无法单击或滚动屏幕。 all components are in scrollview. 所有组件都在滚动视图中。 but I am not able to scroll scrollview when I touch on listviews. 但是当我触摸列表视图时,我无法滚动滚动视图。

here is code where I'm managing height of listview 这是我在管理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;
    }

}`

I tried recyclerview and with this property 我尝试了recyclerview并使用此属性

note_recyclerview.setNestedScrollingEnabled(false);

but I didn't get what I want. 但我没有得到我想要的。

how can I achieve this? 我该如何实现?

Do not use ListView inside ScrollView . 不要在ScrollView使用ListView

As you are using multiple ListView , so you should use android.support.v4.widget.NestedScrollView instead of ScrollView to get proper scrolling behavior. 当您使用多个ListView ,因此应使用android.support.v4.widget.NestedScrollView而不是ScrollView来获得正确的滚动行为。

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. NestedScrollView就像ScrollView一样,但是在新旧版本的Android上,它都同时充当nested滚动parentchild Nested scrolling is enabled by default. 默认情况下启用嵌套滚动。

See documentation . 请参阅文档

Here is an example: 这是一个例子:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/listview1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </ListView>

        <ListView
            android:id="@+id/listview2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </ListView>
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

Hope this will help~ 希望这会有所帮助〜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM