首页 > 解决方案 > ViewGroup.findViewById() 返回 null 因为视图在运行时具有不同的 id

问题描述

额外的信息:

  1. 我们最近从支持库切换到了 androidX。
  2. 片段.xml
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/top_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout>
        <!-- Other views -->
    </LinearLayout>


    <!-- This is the layout i am trying to instantiate -->
    <RelativeLayout
        android:id="@+id/target"/>

</RelativeLayout>

标签: androidandroidxfindviewbyid

解决方案


推荐阅读