Created
December 24, 2013 10:06
-
-
Save sunwicked/8111175 to your computer and use it in GitHub Desktop.
Get dimensions of a view after measurement of view is completed , solves getting view's dimensions as 0 in onCreate()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //root of layout | |
| final View view = findViewById(R.id.root); | |
| ViewTreeObserver vto = view.getViewTreeObserver(); | |
| vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { | |
| @Override | |
| public void onGlobalLayout() { | |
| ViewTreeObserver vto = view.getViewTreeObserver(); | |
| width = profile_Lin.getWidth(); | |
| height = profile_Lin.getHeight(); | |
| profile_Lin.setBackgroundDrawable(createSelector(getResources().getColor( | |
| R.color.profile_new))); | |
| vto.removeGlobalOnLayoutListener(this); | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better approach would be to get the size in onWindowFocusChanged()