Skip to content

Instantly share code, notes, and snippets.

@ZZANZU
Created May 6, 2023 07:00
Show Gist options
  • Save ZZANZU/19cc1dcfc659eb469ea63fb0c9480e64 to your computer and use it in GitHub Desktop.
Save ZZANZU/19cc1dcfc659eb469ea63fb0c9480e64 to your computer and use it in GitHub Desktop.
ViewPager2
/**
* A lot of places in code rely on an assumption that the page fills the whole ViewPager2.
*
* TODO(b/70666617) Allow page width different than width/height 100%/100%
*/
private RecyclerView.OnChildAttachStateChangeListener enforceChildFillListener() {
return new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(@NonNull View view) {
RecyclerView.LayoutParams layoutParams =
(RecyclerView.LayoutParams) view.getLayoutParams();
if (layoutParams.width != LayoutParams.MATCH_PARENT
|| layoutParams.height != LayoutParams.MATCH_PARENT) {
throw new IllegalStateException(
"Pages must fill the whole ViewPager2 (use match_parent)");
}
}
@Override
public void onChildViewDetachedFromWindow(@NonNull View view) {
// nothing
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment