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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:38+00:00 2026-05-27T13:14:38+00:00

I am trying to create a custom ViewGroup, and I want to use it

  • 0

I am trying to create a custom ViewGroup, and I want to use it with a full screen application. I am using the “requestWindowFeature(Window.FEATURE_NO_TITLE)” to hide the title bar. The title bar is not showing, but it still consuming space on top of the window.

Here is a picture of the problem

The image above was generated with the following code:

public class CustomLayoutTestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Button b = new Button(this);
        b.setText("Hello");
        CustomLayout layout = new CustomLayout(this);
        layout.addView(b);
        setContentView(layout);
    }
}

public class CustomLayout extends ViewGroup {
    public CustomLayout(Context context) {
        super(context);
    }
    public CustomLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        Log.i("CustomLayout", "changed="+changed+" l="+l+" t="+t+" r="+r+" b="+b);
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; ++i) {
            final View v = getChildAt(i);
            v.layout(l, t, r, b);
        }
    }
}

(The full Eclipse project is here)

It is interesting to see that it is the Android that is given this space for my custom layout. I am setting the CustomLayout as the root layout of my Activity. In the Log in the “onLayout” is receiving “t=25”, and that is what is pushing my layout down. What I don’t know is what I am doing wrong that makes Android the “t=25” (which is exactly the height of the title bar).

I am running this code in the Android SDK 2.1, but I also happens in Android 2.2.


EDIT: If I change the CustomLayout class for some default layout (such as LinearLayout), the space disappears. Of course, the default layouts of Android SDK don’t create the layout I am trying to create, so that is why I am creating one.

Although the layout I am creating is somewhat complex, this is the smallest code I could create reproducing the problem I have with my layout.

  • 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-27T13:14:39+00:00Added an answer on May 27, 2026 at 1:14 pm

    It’s not a full answer, but in the meantime you can work around the problem by wrapping your custom layout in a <FrameLayout />

    Also, it’s worth noting that your layout extends beyond the bottom of the screen. It’s shifted down by the title bar height (38 pixels in my emulator)

    Edit: Got it. onLayout() (and the corresponding layout() method) specify that the coordinate are not relative to the screen origin, they’re relative to the parent ( http://developer.android.com/reference/android/view/View.html#layout%28int,%20int,%20int,%20int%29 ). So the system is telling you that you’re at relative coordinates (0, 38), and you’re adding it when passing that down to your child, which means that you’re saying that your child is at screen coordinates (0, 76), causing the gap.

    What you actually want to do is:

    v.layout(0, 0, r - l, b - t);
    

    That will put your child Views aligned with the top left corner of your View, with the same width and height as your view.

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

Sidebar

Related Questions

I am trying to create a custom html button on my page using this
I'm trying to create a DialogFragment using a custom view in an AlertDialog .
I am trying to create a custom ListView using an ArrayAdapter . POJO Item
My application is trying to create custom objects from NSImage objects (coming from the
im trying to create a custom macro program in C# and I want to
HIE ALL i am trying to create a custom home screen in android .
I'm trying to create a custom cursoradapter that will use two different layouts depending
I want to create custom row for ListActivity, each row contains Title and List
I am trying to create custom array indexed from 1 using subscript operator. Getting
I am trying to create my custom view through xml, but the screen does

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.