Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:20:41+00:00 2026-05-17T15:20:41+00:00

I have a layout defined in an XML file( base_layout.xml ) which may contain

  • 0

I have a layout defined in an XML file(base_layout.xml) which may contain 20+ ViewStub definitions in addition to 3-5 other views such an ImageView and a LinearLayout containing 3-5 ImageButton views.

Should i be concerned about how many ViewStub views i place in this layout file?

I read on the developer.android site:

A ViewStub is a dumb and lightweight
view. It has no dimension, it does not
draw anything and does not participate
in the layout in any way. This means
that a ViewStub is very cheap to
inflate and very cheap to keep in a
view hierarchy

is it cheap enough to have 20+ of them? not all being inflated of course, just 1-2 at a time.

when i say cheap enough or talk of being concerned, i am regarding performance of the UI

edit:
what i am trying to accomplish:
create a layout XML file which can be the skeleton for all my of activities. in each Activity, i will inflate the correct ViewStub with the activity’s layout. Since i have so many activities requiring the same skeleton, i wish to re-use as much as possible

I have an Activity class which is the parent of almost all of my activities. this parent class calls setContentView(R.layout.base_layout);. for each child activity, all i am doing is inflating the corresponding ViewStub inside base_layout.xml. doing this allows me to have a very customized UI with the same skeleton view used on all of my activity layouts

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:20:41+00:00Added an answer on May 17, 2026 at 3:20 pm

    I don’t think you’ll see a big performance hit. It’s still cheaper than having all of them inflated from the begining.

    The downside of having so many stubs is that you could lose sight of the whole design. Maybe it makes more sense to group several views/items into one viewgroup. Maybe you could explain what you’re attempting to do and see if there is a better way to realize it

    edit:
    Well, instead of having multiple ViewStubs which include different subviews like

    <ViewStub android:id="@+id/stub"
               android:inflatedId="@+id/activity1"
               android:layout="@layout/myActivity1"
               />
    <ViewStub android:id="@+id/stub2"
               android:inflatedId="@+id/activity2"
               android:layout="@layout/myActivity2"
               />
    

    just have a single ViewStub and in your acitivities onCreate() do something like

    setContentView(R.layout.base_layout);
    ViewStub stub = (ViewStub)findViewById(R.id.stub);
    
    stub.setInflateId(R.id.activity1);
    stub.setLayoutResource(R.layout.myActivity2);
    stub.inflate();
    

    This way you’d still have only one ViewStub in your base_layout, which you could setup in code before inflating.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a layout defined in XML. It contains also: <RelativeLayout android:id=@+id/item android:layout_width=fill_parent android:layout_height=wrap_content
I want to populate a table, defined in layout xml file through the programmatic
I have a string defined in my String.xml file that uses format arguments, i.e.:
I have a PreferenceCategory , xml file and I have defined all preferences in
I have a ListActivity where the list items are defined in another XML layout.
I have a button defined in my XML file. The button works exactly like
I have a ViewFlipper defined that contains 3 views... <?xml version=1.0 encoding=utf-8?> <ViewFlipper xmlns:android=http://schemas.android.com/apk/res/android
I have a layout xml file with a linear layout. One of the children
I have a layout which uses min-width and works great. So I came to
I have a TableLayout defined in my xml with three columns and four rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.