Swipe a portion of the page using pager view
I have ViewPager
with PagerTabStrip
, when scrolling from page to another, both the pager and the tab will move together. (for example google paly)
It works fine. now all pages have common data and one part will change when scrolling, so I don't want to scroll the whole page, just an area that will change.
As you can see in the following image, only the red area will be executed when scrolling through the pages, the green area will not move.
I've searched a lot, but I can't find anything useful, any help would be appreciated.
viewpager code:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#FFFFFF"
android:textColor="#003366"
android:paddingTop="4dp"
android:paddingBottom="4dp"/>
</android.support.v4.view.ViewPager>
source to share
Usage swipeyTabs
is the answer. The problem when using PagerTabStrip
is what PagerTabStrip
will be inside the tag ViewPager
, see the following code:
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#FFFFFF"
android:textColor="#003366"
android:paddingTop="4dp"
android:paddingBottom="4dp"/>
</android.support.v4.view.ViewPager>
therefore you cannot separate them from each other. but when using SwipeyTabs each tag will be as a separate part, see the following code:
<net.peterkuterna.android.apps.swipeytabs.SwipeyTabs
android:id="@+id/swipeytabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
swipeytabs:bottomBarColor="#ff96aa39"
swipeytabs:bottomBarHeight="2dip"
swipeytabs:tabIndicatorHeight="3dip"
android:background="#ff3b3b3b"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1" />
In this case, you can customize your layout however you want, dealing with ViewPager
and swipeyTabs
as two parts.
In your case, I think you can put swipeyTabs
both ViewPager
in the red position like in the image and in the green areas you just need to adjust them according to your needs.
I found these links that might help you. Good luck with that.
source to share
Disclaimer: I read your post wrong. Splitting ViewPager
into PagerTabStrip
may not work, or a different approach may be required. I'll leave an answer here in case it helps anyway.
You can achieve this by inserting ViewPager
in a separate slice and placing another independent slice below that is not controlled ViewPager
.
Basically, your main activity consists of two fragments: one that contains ViewPager
(which contains more fragments), the other that contains a fixed view.
This requires nested snippets to be supported, which are only available on Android 4.2 or otherwise in the latest support library (version 11).
Remember, when instantiating your adapter for, ViewPager
you need to use the FragmentManager
returned getChildFragmentManager()
.
source to share