You probably call this onCreate or onStart or onResume, methods that are executed before the layout is measured. But there is a lot of work around, this is one good option:
ViewTreeObserver vto = rootView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { public void onGlobalLayout() { v.getWidth();
If rootView can be any viewGroup at a higher level than the one you want to use for width. But keep in mind that this list may work several times.
source share