Home » Android » android – can i create a nestedScroll Layout like this?

android – can i create a nestedScroll Layout like this?

Posted by: admin June 16, 2020 Leave a comment

Questions:

enter image description here

I think it can be achieved by NestedScrollingChild NestedScrollingParent.

But I can’t really understand them.Who can help me out!

Product manager insists on the design.

The ScrollView contains a LinearLayout ,a “TabLayout” and a ViewPager.

The ViewPager contains 2 fragment contains RecyclerView or just only 2 RecyclerView.

When the ScrollView scroll to Bottom , the RecyclerView can scroll to Bottom.

When the RecyclerView scroll to Top , the ScrollView can scroll to Top.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="1000dp" />
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"></TableLayout>
        <android.support.v4.view.ViewPager
            android:layout_width="match_parent"
            android:layout_height="match_parent"></android.support.v4.view.ViewPager>
    </LinearLayout>
</ScrollView>
How to&Answers:

Just change your ScrollView to android.support.v4.widget.NestedScrollView

Post your xml if that doesn’t work

Answer:

ِYou can do that, but it’s not good at all to use this type of layout

First you need add “wrap_content” abilty ViewPager and RecyclerView’s

ViewPager and RecyclerView

Now you can use scrollview easily, put all item in it

If you want some effect or something when user scrolling or some item get visible in scrolling you can get position of item then make listener on
“OnScrollChangedListener” of scrollview