0

I have ScrollView and inside that a TabLayout. How can I disable the ScrollView from scrolling without effecting on TabLayout scroll?

EDIT:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/scrollview"
android:background="@color/backgroundView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="none"
xmlns:app="http://schemas.android.com/apk/res-auto">


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


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/slider_height"
            android:background="@drawable/border_light"
            >
                      app:pv_progressStyle="@style/LightInColorCircularProgressView"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true" />
            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/main_slider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/slider_height"

                />

            <com.daimajia.slider.library.Indicators.PagerIndicator
                android:id="@+id/custom_indicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                style="@style/AndroidImageSlider_Corner_Oval"
                android:gravity="center"
                android:layout_alignParentBottom="true"

                android:layout_centerHorizontal="true"
                android:layout_marginBottom="10dp" />
        </RelativeLayout>




                .... other stuff


        <com.rey.material.widget.TabPageIndicator
            style="@style/TabPageIndicator"
            android:id="@+id/main_tpi"
            android:layout_height="48dp"
            android:layout_width="match_parent"
            android:paddingLeft="0dp"
            android:clipToPadding="true"
            app:tpi_mode="scroll"
            app:tpi_indicatorColor="@color/colorPrimary"
            android:background="@color/overlayView"/>

        <adapters.CustomViewPager
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/main_vp"

            />

</ScrollView>
Samad
  • 1,776
  • 2
  • 20
  • 35
  • Can you share the relevant code? – madlymad Sep 12 '15 at 19:23
  • http://stackoverflow.com/questions/5763304/disable-scrollview-programmatically – Anis LOUNIS aka AnixPasBesoin Sep 12 '15 at 19:27
  • @madlymad check the edit please – Samad Sep 12 '15 at 19:58
  • Why do you use ScrollView if you want to disable it? – Ilya Blokh Sep 12 '15 at 20:13
  • @IlyaBlokh I want to pin the tablayout to top , as you see it is in bottom but when scroll goes to top I want to disable it so the tab's viewPager only can scroll – Samad Sep 12 '15 at 21:00
  • Although I don't get the hole functionality of the app, I believe that we ought to use the expected functionally of the controllers and not trick our users. So use simple controllers without complicated scrolls or complicated enable, disable algorithms. ;-) – madlymad Sep 16 '15 at 05:30
  • @madlymad what is your suggestion ?! – Samad Sep 17 '15 at 21:43
  • I haven't tried something similar so I am not sure how you could achieve this. There are some libraries that pin tabs or actionbar on top. Also, some of the Android compatibility packages contains such an example... Have you checked out how they do it? IMO. When you scroll up it pins when down unpin. So no need to disable something. Depending on the number and context of the tabs you may use the fillviewport so as to avoid the horizontal scrolling. – madlymad Sep 18 '15 at 06:03

1 Answers1

0

I used this and it worked for me :

// Get the ScrollView
final ScrollView myScroll = (ScrollView) findViewById(R.id.display_scrollview);


// Disable Scrolling by setting up an OnTouchListener to do nothing
myScroll.setOnTouchListener( new OnTouchListener(){ 
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true; 
    }
});


// Enable Scrolling by removing the OnTouchListner
tvDisplayScroll.setOnTouchListener(null);

happy programming......!!!

Amaresh Jana
  • 732
  • 11
  • 22