0

I have written an application that has 11 different relative layouts, all declared in the same file, but only one is showing, the other are hidden. Then I implemented a drawer that allows me to choose which layout showing. The problem is that these layouts are quite heavy (about 3000 lines), so my app runs slow, especially when starting another activity or when using searchview.

How can I avoid this? (I have tried to split the layouts but in this way I can only load one of them one time in the activty and I want to switch between them using the drawer)

asdf
  • 97
  • 1
  • 9

2 Answers2

1

There's only one solution for your issue - start using fragments. Why? Please read carefully texts below:

From: Android Developers Guide - Fragments

Android introduced fragments in Android 3.0 (API level 11), primarily to support more dynamic and flexible UI designs on large screens, such as tablets. Because a tablet's screen is much larger than that of a handset, there's more room to combine and interchange UI components. Fragments allow such designs without the need for you to manage complex changes to the view hierarchy. By dividing the layout of an activity into fragments, you become able to modify the activity's appearance at runtime and preserve those changes in a back stack that's managed by the activity.

From: Android Developers Training - Building a Flexible UI

When designing your application to support a wide range of screen sizes, you can reuse your fragments in different layout configurations to optimize the user experience based on the available screen space.

(...) The FragmentManager class provides methods that allow you to add, remove, and replace fragments to an activity at runtime in order to create a dynamic experience.

You can also read these StackOverFlow posts:

Check also this site to get some great tutorials: [CodePath] Fragments

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 18,034
  • 7
  • 69
  • 86
0

Use <FrameLayout> Tag in your xml and inflate them with different Fragments as required

Take a look at the related documentation. This is exactly what you need: Fragmenting

Alfabravo
  • 7,232
  • 6
  • 43
  • 77
architjn
  • 1,185
  • 1
  • 10
  • 28