简体   繁体   中英

What is the best/cleanest way to implement a swipe view?

It should work similar to the android home screen. Which way has the best performance, is the most common one and cleanest in programming? The number of pages would be between 5 and 25 pages, which will be created dynamically. Thanks

Use the ViewPager . It works with a type of Adapter , so dynamic adding of pages is simple, it is also official and has good performance, so it should suit your needs perfectly.

Do to the amount of pages to be added I would recommend using the FragmentStatePagerAdapter .
This is Google's recommended way of using swipe views if the amount of pages is going to be large.

The problem with the other pager adapters is that they keep the pages in memory, which can use a lot of resources and make you application inefficient.

With the FragmentStatePagerAdapter the pages will not be kept in memory, they will be destroyed every time they leave the foreground. This will save precious resources and make your app blazing fast!!!

With this and appropriate life cycle handling your app will be at Google standards while providing a wonderful UX.

There is a Tutorial in the developer section of the Google's android page for creating swipe viwes with FragmentStatePagerAdapter. Creating Swipe Views with Tabs .

Hope this was helpful!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM