在fragment中findviewbyid的时候,是在fragment上找而不是在fragment所在的Activity上找!!切记,是渲染回来的view,这个错误极具有隐藏性!studio不报错,此时getActivity().findviewbyid是不对滴!!

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab_layout, container, false);
initData(1);
initView(view);
return view;
}
protected void initView(View view) {
// 此时是在fragment上找view,而不是activity上,切记

mRv = (RecyclerView) view.findViewById(R.id.rv);



switch (type) {
case 1:
mRv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
mRv.setItemAnimator(new DefaultItemAnimator());
mRv.setAdapter(mAdapter);
break;

}


}