Skip to content

Instantly share code, notes, and snippets.

@doridori
Last active August 29, 2015 13:56

Revisions

  1. doridori renamed this gist Feb 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. doridori renamed this gist Feb 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. doridori renamed this gist Feb 25, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ViewTreeObserver → ViewTreeObserver.java
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,9 @@ public void onGlobalLayout()
    Log.d("DISPLAY", content.getWidth() + " x " + content.getHeight());

    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
    getView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
    else
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
    });
  4. doridori revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ViewTreeObserver
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //inside a fragment. If an Activity you could use findViewById(Window.ID_ANDROID_CONTENT);
    //inside a fragment. If in an Activity you could use findViewById(Window.ID_ANDROID_CONTENT);
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
  5. doridori revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ViewTreeObserver
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,4 @@ getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.O
    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
    });
    });
  6. doridori renamed this gist Feb 25, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. doridori revised this gist Feb 25, 2014. No changes.
  8. doridori revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //inside a fragment. If an Activity use...
    //inside a fragment. If an Activity you could use findViewById(Window.ID_ANDROID_CONTENT);
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
  9. doridori revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //inside a fragment. If an Actvitiy you could use getContentView()
    //inside a fragment. If an Activity use...
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
  10. doridori revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //inside a fragment
    //inside a fragment. If an Actvitiy you could use getContentView()
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
  11. doridori revised this gist Feb 25, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@
    public void onGlobalLayout()
    {
    //do something like measure a view etc
    View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    Log.d("DISPLAY", content.getWidth() + " x " + content.getHeight());

    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
  12. doridori revised this gist Feb 25, 2014. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    //inside a fragment
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
    public void onGlobalLayout()
    {
    //do something like measure a view etc
    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
    });
    {
    @Override
    public void onGlobalLayout()
    {
    //do something like measure a view etc

    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
    });
  13. doridori created this gist Feb 25, 2014.
    12 changes: 12 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    //inside a fragment
    getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
    @Override
    public void onGlobalLayout()
    {
    //do something like measure a view etc

    //we only wanted the first call back so now remove
    getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
    }
    });