开发者社区> 问答> 正文

为何我这个findviewbyid返回是空的

布局如下:

 fragment_menu.xml主要布局
 android:id="@+id/vNavigation"
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:layout_gravity="start"
 android:background="@android:color/transparent"
 app:headerLayout="@layout/view_global_menu_header"
 app:itemIconTint="#8b8b8b"
 app:itemTextColor="#666666"
 app:menu="@menu/drawer_menu"/>
 view_global_menu_header.xml
 android:id="@+id/vGlobalMenuHeader"
 android:layout_width="match_parent"
 android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/ivMenuUserProfilePhoto"
        android:layout_width="@dimen/global_menu_avatar_size"
        android:layout_height="@dimen/global_menu_avatar_size"
        android:layout_margin="12dp" />

</LinearLayout>

然后是获取

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 View view = inflater.inflate(R.layout.fragment_menu, container,
 false);
 ivMenuUserProfilePhoto = (ImageView) view.findViewById(R.id.ivMenuUserProfilePhoto);
        但是这个`ivMenuUserProfilePhoto`返回是`null`,这是为什么啊?看着好像没问题啊

展开
收起
爵霸 2016-05-30 09:45:00 1897 0
1 条回答
写回答
取消 提交回答
  • 或者去本工程的相近页面拷贝过来import

    2019-07-17 19:19:04
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载