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

  • SEARCH
  • Home
  • 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 7629899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:57:38+00:00 2026-05-31T05:57:38+00:00

I have an activity with a couple of views in a linear layout, one

  • 0

I have an activity with a couple of views in a linear layout, one is a textview and one is the main view of my game, which is a custom view I do things with in code.

When I added the following piece of code into my activity:

mTextView.setText("random text");

The onMeasure() is being called in the custom view, i.e. setText on the textview seems to be causing a different view to re-measure.
Because my onmeasure() code resets the view in a undesirable way, I want to avoid this happening.

What is causing the call to onMeasure() in this case and how can I stop it?

  • 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-31T05:57:39+00:00Added an answer on May 31, 2026 at 5:57 am

    Answer to your question:
    In a linear layout, the size and position of each element depends on the sizes and positions of the elements that come before it. If you use layout weights to size the elements instead of using fixed sizes, moreover, then an element’s size and position also depends on the elements that come after it.

    Changing the contents of one element (in your case by calling setText()) may change the size of that element. As a result, Android does a re-layout to determine the new sizes and positions for the LinearLayout’s children, and this requires all the elements in the linear layout to be measured.

    Answer to your problem:
    It would be wise to assume that onMeasure() can be called at any time. A good solution would be to change onMeasure() so that it has no side-effects. Instead wait for onSizeChanged() before you “reset the view.”

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

Sidebar

Related Questions

I have a couple AsyncTask classes in my main activity, each of which fetches
I have a couple of Activities which all contain one CustomView , a titlebar.
Suppose I have an Activity which has a couple other objects which are doing
I have an Activity with a layout containing a custom ImageView and a few
I have created a custom ViewGroup in which I create a couple of custom
in my app i have activity with XML layout, i want to build an
I am having trouble with my activity management. So I have activity A which
I have an activity with the following layout. So in this screen, initally the
I have an activity with a spinner which loads a simpleCursorAdaptor. I call another
I have a fragment in an activity where I create views dynamically and assign

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.