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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:55:34+00:00 2026-06-04T09:55:34+00:00

It appears to me that there is a problem in Android’s coordinate system. When

  • 0

It appears to me that there is a problem in Android’s coordinate system. When I have a normal view (without requesting FEATURE_NO_TITLE), I then retrieve int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();. This gives me 76px: 38px for the status bar, and 38px for the title bar.

However, if I request FEATURE_NO_TITLE and then repeat the procedure, getTop() returns 0px, despite the fact that the status bar is still visible!

This discrepancy shouldn’t make a difference, because we don’t usually care where the content view starts. However, it does matter to me because I position views on the decor view — which covers the entire visible window.

I know that this is not a trick of the titlebar and the density of the device, because if I request a custom titlebar, and give it 0 height, then getTop() returns 38px.

The solution/workaround is to add 38 pixels manually when requesting FEATURE_NO_TITLE. My question is: is this an Android bug? Or is there something I’m not understanding about how layouts work that would make this behavior understandable?

Thanks in advance!

Here is a minimal program that reproduces the problem. Run it twice, and uncomment the indicated line. I am compiling against Android SDK 7, and running on a Samsung Galaxy S with Android 2.3.4.

Layout: main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutParent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/someId"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </LinearLayout>

</RelativeLayout>

Code: TestStatusBarActivity.java

package com.test.teststatusbar;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.Window;
import android.widget.RelativeLayout;

public class TestStatusBarActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Uncomment the following line to see the alternate behavior
        //requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.main);

        RelativeLayout layoutParent = (RelativeLayout) findViewById(R.id.layoutParent);
        View something = findViewById(R.id.someId);
        something.setBackgroundColor(Color.CYAN);

        ViewTreeObserver vto = layoutParent.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {

                // decor window top
                Rect rectgle = new Rect();
                Window window = getWindow();
                window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
                int StatusBarHeight = rectgle.top;

                // "content view" top
                int contentViewTop = window.findViewById(
                        Window.ID_ANDROID_CONTENT).getTop();

                int TitleBarHeight = contentViewTop - StatusBarHeight;

                Log.i("STATUSBARTEST", "StatusBar Height = " + StatusBarHeight
                        + " , TitleBar Height = " + TitleBarHeight
                        + ", Content top = " + contentViewTop);
            }
        });

    }
}

References

  • Similar question that seems to sidestep the issue?
  • Source question that helped make this example
  • 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-06-04T09:55:35+00:00Added an answer on June 4, 2026 at 9:55 am

    is this an Android bug?

    No. The system just builds the view hierachy slightly different in both cases do avoid unneccessary depth (for performance reasons, more (nested) layout elements mean more overhead).

    Here is how the hierachy looks with a titlebar:

    Note: my pixel values are slightly different from yours because I ran your sample on a smaller emulator. That shouldn’t matter for this case.

    enter image description here
    full size

    The basic LinearLayout that holds the titlebar and your content layout fills the whole display. It also has a padding of 25px here, because the status bar overlays the normal UI hierachy. So there has to be some space reserved via padding.

    Then follows the titlebar as the first element of the LinearLayout, also with 25 px height. Which means that findViewById(Window.ID_ANDROID_CONTENT).getTop(); returns 50 in total, because the contentview FrameLayout is 50 pixels from the top of it’s parent LinearLayout (again 25 padding + 25 title). Which is correct.

    So, what happens when the titlebar gets removed?

    enter image description here
    full size

    The system strips the outer LinearLayout completely, which means that the contentview now fills the whole screen. findViewById(Window.ID_ANDROID_CONTENT).getTop(); should return 0 here, what it infact does. This is not wrong. But there has to be reserved space for the statusbar again. The system assigned that padding to the contentview here.

    How to fix it

    I think the solution is pretty straightforward: You have to include the padding of the contentview to get exact results. E.g. change

    int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
    

    to

    View contentView = window.findViewById(Window.ID_ANDROID_CONTENT);
    int contentViewTop = contentView.getTop() + contentView.getPaddingTop();
    

    This prints the correct results for me.

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

Sidebar

Related Questions

I have an android app that appears to be working fine - but I
Making websites that appear correctly in IE is a big problem. Is there any
It appears that ffmpeg now has a segmenter in it, or at least there
Is there an option to enable the drop down menu that appears when coding
Is there an event that fires in vb.net just before a contextMenuStrip appears when
It appears that we will have to build/deploy one of our new JBoss apps
I have developed an android app that mainly targets smartphones. However in tablet emulator
I have an Android app that allows the user to record data (such as
I have a strange problem with my Android app. When I start it from
I'm having a problem with a text view embedded in a ScrollView. That is,

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.