Skip to content Skip to sidebar Skip to footer

Coordinatorlayout Not Scrolling With Swiperefreshlayout

I have added coordinatorlayout+viewpager+TabLayout and have added three tabs with viewpager but scrolling only works with first tab(recent) not working with two tabs 1. contact,2.s

Solution 1:

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/main_content"android:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"><android.support.design.widget.AppBarLayoutandroid:id="@+id/appbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"android:fitsSystemWindows="true"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:popupTheme="@style/ThemeOverlay.AppCompat.Light"app:layout_scrollFlags="scroll|enterAlways|snap" /><android.support.design.widget.TabLayoutandroid:id="@+id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabGravity="fill"app:tabMaxWidth="0dp"android:fillViewport="false" /></android.support.design.widget.AppBarLayout><android.support.v4.view.ViewPagerandroid:id="@+id/viewpager"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_behavior="@string/appbar_scrolling_view_behavior" /></android.support.design.widget.CoordinatorLayout>

Solution 2:

MainActivity:

publicclassMainActivityextendsAppCompatActivity {

    Toolbar toolbar;
    AppBarLayout appBarLayout;
    ViewPager viewPager;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bindView();
    }

    publicvoidbindView() {
        appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("RECENT");
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        viewPager = (ViewPager) findViewById(R.id.viewpager);
        setupViewPager(viewPager);
        TabLayout tabLayout;
        tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setSelected(true);
        viewPager.setCurrentItem(0);


        viewPager.addOnPageChangeListener(newTabLayout.TabLayoutOnPageChangeListener(tabLayout));

        tabLayout.addOnTabSelectedListener(newTabLayout.OnTabSelectedListener() {
            @OverridepublicvoidonTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition()) {
                    case0:
                        viewPager.setCurrentItem(0);
                        toolbar.setTitle("RECENT");
                        break;
                    case1:
                        viewPager.setCurrentItem(1);
                        toolbar.setTitle("CONTACT");
                        break;
                    case2:
                        viewPager.setCurrentItem(2);
                        toolbar.setTitle("SETTING");
                        break;
                    default:
                        viewPager.setCurrentItem(0);
                        toolbar.setTitle("RECENT");
                        break;
                }
            /*if (viewPager.getCurrentItem() == 0) {
                toolbar.setTitle(viewPager.getCurrentItem());
            }*/
            }

            @OverridepublicvoidonTabUnselected(TabLayout.Tab tab) {

            }

            @OverridepublicvoidonTabReselected(TabLayout.Tab tab) {

            }
        });
        viewPager.addOnPageChangeListener(newViewPager.OnPageChangeListener() {
            @OverridepublicvoidonPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @OverridepublicvoidonPageSelected(int position) {
                if (viewPager.getCurrentItem() == 0) {
                    toolbar.setTitle("RECENT");
                }

            }

            @OverridepublicvoidonPageScrollStateChanged(int state) {

            }
        });


    }

    privatevoidsetupViewPager(ViewPager viewPager) {
        ViewPagerAdapteradapter=newViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(newFragmentOne(), "RECENT");
        adapter.addFragment(newFragmenttwo(), "CONTACT");
        adapter.addFragment(newFragmentThree(), "SETTING");
        viewPager.setAdapter(adapter);

    }

    classViewPagerAdapterextendsFragmentPagerAdapter {
        privatefinal List<Fragment> mFragmentList = newArrayList<>();
        privatefinal List<String> mFragmentTitleList = newArrayList<>();

        publicViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Overridepublic Fragment getItem(int position) {

            return mFragmentList.get(position);
        }

        @OverridepublicintgetCount() {
            return mFragmentList.size();
        }

        publicvoidaddFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Overridepublic CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }
}

activity_main:

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/main_layout"android:layout_width="match_parent"android:layout_height="match_parent"
    ><android.support.design.widget.AppBarLayoutandroid:id="@+id/appBarLayout"android:layout_width="match_parent"android:layout_height="wrap_content"app:elevation="6dp"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:layout_alignParentTop="true"android:background="?attr/colorPrimary"android:minHeight="?attr/actionBarSize"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"app:elevation="0dp"app:layout_scrollFlags="scroll|enterAlways"app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /><android.support.design.widget.TabLayoutandroid:id="@+id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/toolbar"android:background="?attr/colorPrimary"android:minHeight="?attr/actionBarSize"app:elevation="0dp"app:tabGravity="fill"app:tabIndicatorColor="#FFF"app:tabMode="fixed"app:tabSelectedTextColor="#ffffff"app:tabTextColor="#FFF" /></android.support.design.widget.AppBarLayout><android.support.v4.view.ViewPagerandroid:id="@+id/viewpager"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/tab_layout"app:layout_behavior="@string/appbar_scrolling_view_behavior" /></android.support.design.widget.CoordinatorLayout>

Fragment One:

publicclassFragmentOneextendsFragment {

    publicFragmentOne(){

    }
    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragmentfinalViewoneFra= inflater.inflate(R.layout.fragment_one, container, false);


        return oneFra;
    }

}

fragment_one:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="nvojnvg"/></LinearLayout>

Fragmenttwo:

publicclassFragmenttwoextendsFragment {

    publicFragmenttwo(){

    }
    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragmentfinalViewoneFra= inflater.inflate(R.layout.contact_fragment, container, false);


        return oneFra;
    }

}

contact_fragment xml:

<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.SwipeRefreshLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/swipe_refresh_layout"android:layout_width="match_parent"android:layout_height="wrap_content"app:layout_behavior="@string/appbar_scrolling_view_behavior"><!-- place your view here --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><android.support.v7.widget.RecyclerViewandroid:id="@+id/recyclerview_registered"android:layout_width="match_parent"android:layout_height="wrap_content"android:scrollbars="vertical" /><Viewandroid:layout_width="match_parent"android:layout_height="2dp"android:layout_marginTop="2dp"android:background="#CCC" /><android.support.v7.widget.RecyclerViewandroid:id="@+id/recyclerview_invite"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="2dp"android:scrollbars="vertical" /></LinearLayout></android.support.v4.widget.SwipeRefreshLayout>

FragmentThree:

publicclassFragmentThreeextendsFragment {

    publicFragmentThree(){

    }
    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragmentfinalViewoneFra= inflater.inflate(R.layout.setting_fragment, container, false);


        return oneFra;
    }

}

setting_fragment xml:

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><android.support.v7.widget.RecyclerViewandroid:id="@+id/recyclerview"android:layout_width="match_parent"android:layout_height="match_parent"android:scrollbars="vertical" /></RelativeLayout>

Change Your Theme in Style:

 android:theme="@style/AppTheme.Base"

    <stylename="AppTheme.Base"parent="Theme.AppCompat.Light.NoActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/colorPrimary</item><itemname="colorPrimaryDark">@color/colorPrimaryDark</item><itemname="colorAccent">@color/colorAccent</item><itemname="windowNoTitle">true</item><itemname="windowActionBar">false</item><itemname="android:textColorPrimary">#1E1E1E</item><itemname="colorControlNormal">#1E1E1E</item><itemname="colorControlActivated">#BCBCBC</item><itemname="android:splitMotionEvents">false</item><itemname="android:windowEnableSplitTouch">false</item></style>

See the image

Post a Comment for "Coordinatorlayout Not Scrolling With Swiperefreshlayout"