Last active
December 21, 2015 03:16
-
-
Save ityancs/c4513ff54e89c1064b19 to your computer and use it in GitHub Desktop.
This file contains 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
public class measureSize{ | |
public void getSize1(){ | |
int w = View.MeasureSpec.makeMeasureSpec(0, | |
View.MeasureSpec.UNSPECIFIED); | |
int h = View.MeasureSpec.makeMeasureSpec(0, | |
View.MeasureSpec.UNSPECIFIED); | |
imageView.measure(w, h); | |
int height = imageView.getMeasuredHeight(); | |
int width = imageView.getMeasuredWidth(); | |
} | |
public void getSize2(){ | |
ViewTreeObserver vto = imageView.getViewTreeObserver(); | |
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { | |
public boolean onPreDraw() { | |
vto.removeOnPreDrawListener(this); | |
int height = imageView.getMeasuredHeight(); | |
int width = imageView.getMeasuredWidth(); | |
return true; | |
} | |
}); | |
} | |
public void getSize3(){ | |
ViewTreeObserver vto = imageView.getViewTreeObserver(); | |
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this); | |
imageView.getHeight(); | |
imageView.getWidth(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment