Size grid
m4rtinsp opened this issue · 1 comments
m4rtinsp commented
Hello everyone!
Is there any way to know the height of the grid after you set the adapter?
Thanks!
tibbi commented
you can get it after the view has been drawn, my way is quite ugly, but I do it like
StaggeredGridView meetupGridView = ...
final ViewTreeObserver vto = meetupGridView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < 16) {
meetupGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
meetupGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
int height = meetupGridView.getHeight();
}
});