如何禁用Scrollview

时间:2015-09-12 18:50:51

标签: android android-scrollview

我有ScrollView,内有TabLayout。如何禁用ScrollView滚动而不影响TabLayout滚动?

修改

<?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>

1 个答案:

答案 0 :(得分:0)

我用过这个,它对我有用:

// 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);
快乐编程...... !!!