Meenaxi
Meenaxi

Reputation: 567

make page scroll disable in pagerslidingtabstrip

Can we disable page sliding in PagerSlidingTabStrip ? I am using PagerSlidingTabStrip where tabs are created dynamically in my example. On each fragment there are tow buttons

  1. Chapter wise analysis
  2. Rank wise analysis

What i want is when user click on Rank wise analysis Sliding should disable and tabs get hide and when click on Chapter wise analysis tabs should visible again and sliding should also enable. How to achieve this? Tabs hide and show is working properly but am not able to make slide disable.

Upvotes: 1

Views: 1286

Answers (3)

Meenaxi
Meenaxi

Reputation: 567

Here is my solution.... I make slight changes with my layout.Previously i had 2 buttons on each fragment. Now i place that two button in parent activity.. here is my xml file.

<RelativeLayout xmlns: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:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
    android:id="@+id/lintab"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.joyoflearning.utils.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dip"
        android:background="@drawable/background_tab" />
</LinearLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/lintab"
    android:background="@drawable/background_tab"
    tools:context=".TestAnalysisActivity" />

<LinearLayout
    android:id="@+id/RankAnalysisFragment"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/linButtons"
    android:orientation="vertical" >
</LinearLayout>

<LinearLayout
    android:id="@+id/linButtons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/darkGray"
    android:gravity="center_horizontal"
    android:orientation="horizontal"
    android:paddingBottom="5dp"
    android:paddingTop="5dp" >

    <Button
        android:id="@+id/btnChapterWise"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:background="@drawable/btn_blue_bg"
        android:drawableLeft="@drawable/checkbtn_icon"
        android:drawablePadding="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Chapterwise"
        android:textColor="#ffffff" />

    <Button
        android:id="@+id/btnRankWise"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginLeft="10dp"
        android:background="@drawable/btn_blue_bg"
        android:drawableLeft="@drawable/uncheckbtn_icon"
        android:drawablePadding="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Rankwise"
        android:textColor="#ffffff" />
</LinearLayout>

Now click on ChapterWiseAnalysisbutton will hide LinerLayout having id RankAnalysisFragment and click on RankWiseAnalysis will hide Tabs,ViewPager and add a fragment to LinerLayout .

Upvotes: 0

Pankaj
Pankaj

Reputation: 2110

Create a separate class which should extend ViewPager:

public class CustomViewPager extends ViewPager {

public CustomViewPager(Context context) {
    super(context);
}

public CustomViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    // Never allow swiping to switch between pages
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Never allow swiping to switch between pages
    return false;
}
}

And then use this viewPager to set in your xml file like this:

<com.packagename.CustomViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

Then in your activity, set your FragmentPagerAdapter to this viewPager:

mViewPager.setAdapter(YourFragmentPagerAdapter)

Upvotes: 1

Keith Ellis
Keith Ellis

Reputation: 26

Extend ViewPager and override onInterceptTouchEvent() and onTouchEvent().

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    return false;
}

Upvotes: 1

Related Questions