ListView doesn't scroll inside NestedScrollView in android

I fanned a snippet from a view pager that uses listview. And the list view does not support setNestedScrollingEnabled in pre lollipop devices. So I added the list to NestedScrollView, but when scrolling through the list, it does not scroll.

 <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:id="@+id/fragment_item_view"
    android:background="@color/white"
    android:isScrollContainer="true">

<ProgressBar
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:layout_centerInParent="true" />

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fillViewport="true">
        <ListView
            android:id="@+id/list_item_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            android:clipToPadding="false"
            android:divider="@color/gray_stroke_color"
            android:dividerHeight="0.5dp"
            android:paddingBottom="@dimen/padding_64dp"                >
        </ListView>

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

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

</RelativeLayout>

Can anyone suggest me some solution. Thanks in advance.

+7
source share
6 answers

Try using

setNestedScrollingEnabled(true);
+5
source

Use ViewCompat.setNestedScrollingEnabled () and your problem will be solved.

+3
source

, ListView ScrollView, / .

ListView ScrollView.

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ListView
        android:id="@+id/list_item_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        android:clipToPadding="false"
        android:divider="@color/gray_stroke_color"
        android:dividerHeight="0.5dp"
        android:paddingBottom="@dimen/padding_64dp"/>

    </ListView>

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

, RecyclerView ListView, NestedScrollingChild.

, , NestedScrollView . scrollview, 2 scrollviews:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

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

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

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

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

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

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

</LinearLayout>
</ScrollView>

, , , , CoordinatorLayout, . , "app: layout_behavior =" @string/appbar_scrolling_view_behavior " ScrollView: ListView, RecyclerView NestedScrollView.

+1

outerScrollView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                findViewById(R.id.inner_scroll).getParent()
                        .requestDisallowInterceptTouchEvent(false);
                return false;
            }
        });

        innerScrollView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });
0
source

its working if you add this android code: nestedScrollingEnabled = "true"

 <ExpandableListView
    android:id="@+id/lvExp"
    android:nestedScrollingEnabled="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    />
0
source
yourtListViewName.setNestedScrollingEnabled(true);
0
source

Source: https://habr.com/ru/post/1657487/


All Articles