0

I've been trying to figure this out for the past week. I am an absolute beginner and have been learning stuff on my own.

So i have this ViewPager that displays fragments that have the same layout: an ImageView at the top, and a TextView at the center.

When I swipe between fragments, the imageviews and textviews get animated together and that's fine.

There are a sections however, where i want the textviews to swipe, but the image views to stay put, but will go back to swipe after one or two fragment swipes

Please take a look at this illustration: The slightly darker blue fragment is the effect that i want.

Think of it like an iOS contacts list where a letter of the alphabet, for example "A", stays put as a header when swiping through names that begin with that letter.

I've made a PageTransformer work for the whole viewpager but when i try to do it between ImageViews, it sort of works but everything gets messed up and eventually crashes.

Avetard
  • 23
  • 5
  • can you recording some video or gif to illustrating? – VinceStyling Nov 17 '14 at 04:13
  • i am also a android beginner, i found website that's provide a best library [link](http://www.icloudshare.in) – deep Nov 17 '14 at 05:22
  • @VinceStyling I replaced my illustration with a GIF – Avetard Nov 17 '14 at 07:12
  • so according to my understand, there are have AlphaSection and NamesSection, when swiping the NamesSection, checking if the coming page whether satisfy to swipe the AlhpaSection parallel or not. I have a question, can user swiping over the AlphaSection to control the NamesSection? this could be difficult. – VinceStyling Nov 17 '14 at 08:13
  • @Vince, no. The user does not have to swipe over the "AlphaSection". – Avetard Nov 17 '14 at 13:08

3 Answers3

0

You can try viewpager within viewpager for the textView.

Similar question: ViewPager inside ViewPager.

Another way that I can think of is to register a listener to the textview and if the user pressed down and scroll it will check if there are more text. If there is the fragment will be replaced by the next text.

Example:
text.setOnClickListener(new View.OnClickListener()
{
    ACTION.DOWN:
        if(there is more text)
        {
             //replaced text fragment with new text;
        }
}
Community
  • 1
  • 1
user3806339
  • 144
  • 1
  • 2
  • I've tried adding another viewpager knowing it might conflict with other touch events, but i've never tried putting one inside another. I'll try that out. – Avetard Nov 17 '14 at 07:02
0

I just added a viewpager inside a fragment, that is inside another viewpager without adding extra code to the main activity. It worked just the way i wanted it to, albeit unexpectedly. But now my navigation button skips some pages inside the nested viewpager.

Apparently, this feature has been available for quite some time.

Avetard
  • 23
  • 5
0

Alright, I encountered some troubles to release my code yesterday. I'm very interested in this effect, so I've practiced this and successfully to accomplished. The whole project was publish in my github, following is my effort's result.

animation_live

VinceStyling
  • 3,707
  • 3
  • 29
  • 44
  • Haven't imported the files completely yet but i've installed the apk and it is exactly what i wanted, Though, I've successfully implemented it with something as simple as adding a viewpager inside the child fragment. The buttons work the way I wanted it to! I just posted a question about it. Thank you! – Avetard Nov 19 '14 at 05:32
  • I went over your source files and you know what, this app is how I wanted my app to behave but the implementation is totally not what I had expected since i'm working with fragments inside a viewpager that is also inside a fragment inside a viewpager. But i feel like i'm close. Thank you for your effort. – Avetard Nov 19 '14 at 05:53
  • yes, my effort wasn't stand on the real position, but the core logical is fixed, i wish this can be the solution that achieved the most complex part of the effect. then the next job is apply to the real situation of yours. – VinceStyling Nov 19 '14 at 06:12
  • Your solution is actually programatically elegant and uses little resources, I might adapt something from it in a future revision of my app. Regardless, I have solved my problem using a viewpager within a viewpager, but another problem arose from it: http://stackoverflow.com/questions/27008911/navigation-between-viewpager-and-nested-viewpager – Avetard Nov 19 '14 at 06:26
  • As I ever said before, this could be difficult. – VinceStyling Nov 19 '14 at 07:12