0

Hey I am trying to implement a vertical viewpager and been been successful so far. But when I scroll down to get to my second fragment which is blank with an orange background the textviews from my inital fragment are shown.

Inital View

Pic 1

After Scrolling

Pic2

I implemented the vertical pager from this answer (the first one with 180 upvotes)

My project is also on github

If you got any questions feel free to ask in the comments :)

Community
  • 1
  • 1
Johannes Gnadlinger
  • 1,339
  • 1
  • 12
  • 32

2 Answers2

0

Provide to first fragment a colored background(can be transparent also or white) it should resolve it. You can use for transparent the following: android:background="@android:color/transparent"

BNAndroid
  • 158
  • 4
  • Thank you for your answer I tried to set the background of my activity_main with the textviews and the fragment_main with the text views in it did not work – Johannes Gnadlinger Jul 29 '17 at 19:02
0

Looking at your project in GitHub, your TextViews are being added to the R.id.innerLay LinearLayout, which is in your Activity, but they're are not in any of the fragments which are part of the R.id.pager ViewPager. You need to move the TextViews to the R.layout.fragment_main which will prevent them from showing in R.layout.fragment_second

ono
  • 2,984
  • 9
  • 43
  • 85
  • Thank you for your answer! I made the changes but now I got every text view twice I think and the problem is still here. I pushed my changes on my github repo – Johannes Gnadlinger Jul 29 '17 at 18:59
  • Move the `val inLay = findViewById(R.id.innerLay) as LinearLayout for (x in 0..9) { inLay.addView(getView(x)) }` and `getView()` method from your Activity to the fragment and see if it works. – ono Jul 29 '17 at 19:06
  • no did not work this cannot be the problem. With this code I initialize my horizontal view so I dont think that the problem is there – Johannes Gnadlinger Jul 29 '17 at 19:19