how to get width of view when initializing without any listeners?

97 views Asked by At

I need to get width of view that is smaller that default window width. I tried getViewTreeObserver, but it is only executed at the end of all draws that is why variable needed is 0;

I tried to call my fragment(which will use the width) in the listener, but there apeared exception:

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=20986, uid=10161 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

I cant sove this problem. HELP

this also doesnt work:

measure(View.MEASURED_SIZE_MASK, View.MEASURED_SIZE_MASK);
getMeasuredWidth()
getWidth()
0

There are 0 answers