Calling getWidth of parent in onCreateViewHolder
问题 Is it ok to get parent's width in onCreateViewHolder at RecyclerView adapter? Are parent's dimensions measured at that state so I don't get 0 when I call getWidth() on parent? 回答1: Yes, the parent is actually the RecyclerView . It has both a non-zero getWidth() and getMeasuredWidth() by the time onCreateViewHolder is called. Easy way to verify this is set your debugger to stop in the method and inspect the parent. parent = android.support.v7.widget.RecyclerView{d08d560 VFED..... ......ID 0,0