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 6181149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:58:12+00:00 2026-05-24T00:58:12+00:00

Short and sweet summary: When changing a class from View -derived to ViewGroup -derived,

  • 0

Short and sweet summary:

When changing a class from View-derived to ViewGroup-derived, the height and/or width params passed to onSizeChanged are not consistent for my class when used inside of a LinearLayout. Is there any additional information I need to supply when using ViewGroup as a super class to achieve consistent results?

Long version:

I have created a custom View-derived visual control that I’m using like a custom button. I derive from View and then add it to my layouts like this:

class declaration:

public class GameButton extends View {

xml:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:orientation="horizontal"
        android:layout_weight="1">
        <com.myname.myapp.controls.GameButton
            android:id="@+id/button1"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

I want to get a little fancier with the control, so I have changed it to derive from ViewGroup or any subclass of ViewGroup (currently trying to make it a RelativeLayout, for example). As soon as I do this, it disappears.

I added logging to see the values being passed to onSizeChanged, and I’m getting 0 height being passed to onSizeChanged for every instance of my control with no change to the layout xml (above) that works otherwise when I derive directly from View.

Do I need to add any additional hints, params or layout parameters either to the xml or in code when switching from View to ViewGroup?

  • 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-24T00:58:13+00:00Added an answer on May 24, 2026 at 12:58 am

    You need to implement onMeasure() to tell the toolkit that size you are (you must call setMeasuredDimension() at the end of onMeasure().) ViewGroup, by default, compute their size based on their children and you don’t have any here, so the size is 0x0.

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

Sidebar

Related Questions

Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short and sweet: Why does the following block of Objective-C code not produce a
Short and sweet: How can I tell Interface Builder to center a window on
Short and sweet, Is it ok to use (current version) Ruby 1.9.1 with Rails
Short and sweet version: On one machine out of around a hundred test machines
Short and sweet version: Is there a single web service method that would return
Short and sweet question: I've inherited a Pylons site with a bunch of models.
I'll keep it short and sweet - I'm building an application just for practice
Basically, my question is short and sweet: Is the following a bad idea (encapsulating
Good afternoon, OK, short and sweet. I need to get the number of bytes

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.