Search code examples
androidlayoutandroid-activityviewflipper

Best practice for viewflipper containing 10 linearlayouts?


I'm embarking on a GUI Activity composed of a viewflipper, which I would like to contain 10 linearlayout layouts.

Is it advisable to put all of my layouts into the same XML resource/layout file?

If not, is there a more organized approach to coding a viewflipper with many layouts?

Will having everything in the same file come at a significant performance cost?


Solution

  • Personally, i would use the include tag for each separate view. So you can define a main xml where all the include tags are defined. in the following an example:

    <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/flipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <include android:id="@+id/libraryView"  layout="@layout/library_view" />
        <include android:id="@+id/bookView"  layout="@layout/book_view" />
        <include android:id="@+id/workspaceView" layout="@layout/workspace_view" />
    </ViewFlipper>
    

    i defined a ViewFlipper and added some layout resources with the include tag. In this example you would have to define

    library_view.xml
    book_view.xml
    workspace_view.xml
    

    Hope this could help