0

I am working on an existing app which is using a ViewFlipper to switch between views (inside a fragment). With ViewFlipper you don't have well separation of concerns, in my opinion. You have a long fragment class (or an activity) with hundreds of lines of code, and in this fragment/activity, you create different views (not widgets, I mean sub-screens) on the fly and add them to the ViewFlipper as its child, and then you switch between these child on the occurance of a specific event (mainly clicks).

When you use fragments for different views or subscreens of another fragment (a tab or a navigation drawer entry), you put logically different subsections of the main fragment's layout file into different layout files (relating to different fragments, each representing a subscreen), you pull the irrelevant code out of the main fragment, and put it in the related fragment's code, so your main fragment's code is much shorter and cleaner. I consider it a big refactoring.

But in terms of performance and smoothness, I think using a ViewFlipper is probably smoother and faster than doing a fragment transaction. Am I right? What is the best practice for changing/switching between views? Is there any other way for doing this?

I am aware of this question, but I am looking for a performance comparison, I would like to know if there is any other way to switch views and to know which approach makes more sense and is better. In addition, that question is old and Android has evolved ever since.

Community
  • 1
  • 1
Javad
  • 5,755
  • 4
  • 41
  • 51

0 Answers0