Skip to content
Stanislav Koshutsky edited this page Mar 6, 2017 · 1 revision

ViewSizeHelper is a handy and one of most used class which is basically a wrapper of View ViewTreeObserver GlobalLayoutListener. It is used to detect a view size (height and width) at a run time:

public static void requestViewSize(final View view, final IViewSize callBack)

IViewSize is an interface used to deliver view size:

public interface IViewSize {
	void onGotViewSize(int height, int width);
}

Also this class is good if you need to set View's dimensions (height or width) at a run time.

public static void setHeightAndWidth(View view2Fix, int targetHeight, int targetWidth)
public static void setHeight(View view2Fix, int targetHeight)
public static void setWidth(View view2Fix, int targetWidth)

If you need to fix height or width of a displaying image view respecting image aspect ratio:

public static int fixHeight(View view2Fix, Bitmap bitmap, int targetWidth)  
public static int fixWidth(View view2Fix, Bitmap bitmap, int targetHeight)  
Clone this wiki locally