Glückwunsch! Deine Unterstützung wurde an den Autor gesendet
avatar
Multiple Pages in ViewPager Android

Multiple Pages in ViewPager Android

Veröffentlicht am 3, Aug., 2020 Aktualisiert am 3, Aug., 2020 Technik
time 1 min
1
Liebe ich
0
Solidarität
0
Wow
thumb Kommentar
lecture Lesezeit
4
Reaktion

Dies ist der letzte Artikel, den du diesen Monat ohne Anmeldung lesen kannst.

Um die Begrenzung aufzuheben und alle neuen Funktionen nutzen zu können, log dich ein oder erstelle ein Konto, indem du auf den Link unten klickst. Alles ist kostenlos! Einloggen

Multiple Pages in ViewPager Android

Nowadays In Android applications, we often have seen custom designs throughout the application, Which makes UI more beautiful. So in that case, I have experienced some custom design implementation, In which I need to show the two pages in a single View. 

In this article, we will learn how we can show the multiple pages in a ViewPager like the below screenshot:

 


The following steps we need to follow to achieve the above layout.

Step1: Add a ViewPager in your layout file like the below code snippet.

<androidx.viewpager.widget.ViewPager
android:id="@+id/rv_collection_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp" />

 Step2: Make a ViewPager Item UI, as per our design above.

 Step3: Create an Adapter class and override the function `onPageWidth'  and set the value to 0.5f to divide the two pages in single views, like the below code snippet.

override fun getPageWidth(position: Int): Float {
return 0.5f
}

Step4: Now, just run your application and see the result.


Conclusion

This article taught you how you can simply add multiple pages in ViewPager with the help of an override function called onPageWidth()

I hope this article is helpful. If you think something is missing, have questions, or would like to offer any thoughts or suggestions, go ahead and leave a comment below. I’d appreciate the feedback.

I’ve written some other Android-related content, and if you liked what you read here, you’ll probably also enjoy these:


Sharing (knowledge) is caring 😊 Thanks for reading this article. Be sure to clap or recommend this article if you found it helpful. It means a lot to me.

If you need any help then Join me on TwitterLinkedInGitHuband Subscribe to my Youtube Channel.

lecture 3520 Aufrufe
thumb Kommentar
4
Reaktion

Kommentar (0)

Du musst dich einloggen, um kommentieren zu können. Einloggen

Dir gefallen die Artikel von Panodyssey?
Unterstütze die freien Autoren!

Die Reise durch dieses Themengebiet verlängern Technik
Parapluie
Parapluie

Un mot d'un dictionnaire, ma définition, votre sourire, ma joie.A l'en croire, une v...

Bernard Ducosson
1 min
Grue
Grue

Un mot d'un dictionnaire, ma définition, votre sourire, ma joieGros oiseau des levages qui sur la j...

Bernard Ducosson
1 min
Panodyssey sévèrement attaqué
Panodyssey sévèrement attaqué

Bonjour,Je déduis fortement que Panodyssey vient de subir une méchante attaque.Cela grâce à mes multiples webm...

Bruno Druille
1 min

donate Du kannst deine Lieblingsautoren unterstützen

promo

Download the Panodyssey mobile app