get Content Offset From Top View - Android User Interface

Android examples for User Interface:View Margin

Description

get Content Offset From Top View

Demo Code


//package com.java2s;

import android.graphics.Rect;
import android.view.View;
import android.view.Window;

public class Main {
    private static Rect mStatusBarRect = new Rect();

    public static int getContentOffsetFromTop(View view) {
        int offset = view.getRootView()
                .findViewById(Window.ID_ANDROID_CONTENT).getTop();

        if (offset == 0) {
            view.getWindowVisibleDisplayFrame(mStatusBarRect);
            offset = mStatusBarRect.top;
        }//from   w w w  .  ja  va2  s.  c o  m

        return offset;
    }
}

Related Tutorials