Android ImageView不是';动态添加到LinearLayout时不显示

Android ImageView不是';动态添加到LinearLayout时不显示,android,android-layout,dynamic,view,android-support-library,Android,Android Layout,Dynamic,View,Android Support Library,我正在使用一个支持库compile'com.android.support:support-v4:25.1.1' 当我尝试将视图动态添加到其他布局时,图像丢失 app:srcCompat=“@drawable/ic\u remove\u task”在图像视图中使用此选项时,图像不会显示 当我这样写的时候,它就工作了。android:src=“@drawable/ic\u remove\u task” 有什么不对劲吗 这是图像视图 代码在这里,来自上一个问题: 从Android支持库23.3.

我正在使用一个支持库
compile'com.android.support:support-v4:25.1.1'
当我尝试将视图动态添加到其他布局时,图像丢失

app:srcCompat=“@drawable/ic\u remove\u task”
在图像视图中使用此选项时,图像不会显示

当我这样写的时候,它就工作了。
android:src=“@drawable/ic\u remove\u task”

有什么不对劲吗

这是图像视图

代码在这里,来自上一个问题:

从Android支持库23.3.0开始,支持向量可绘制文件只能通过app:srcCompat加载

您需要将vectorDrawables.useSupportLibrary=true添加到build.gradle文件中

    // Gradle Plugin 2.0+  
 android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }  
并确保应用程序使用正确的命名空间,如下所示:

xmlns:app="http://schemas.android.com/apk/res-auto"

我已经自己解决了。问题在于夸大了观点。 您必须按如下方式初始化充气机:

LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
与此相反:

 LayoutInflater layoutInflater = (LayoutInflater) activity.getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

显示完整的代码。那里可能发生了很多事情。您是否设置了
线性布局的大小?你在哪里加的?你确定它被添加了吗?是图像向量吗?@JonZarate,我编辑了一个问题并在上面添加了一个代码。@Pulkit,是的,图像是向量。我的gradle代码中已经有这个(
defaultConfig{vectorDrawables.useSupportLibrary=true}
检查xml文件中这行代码后面的xmlns:appIn layout?或imagein layout的名称空间
xmlns:android=”http://schemas.android.com/apk/res/android“
add
xmlns:app=”http://schemas.android.com/apk/res-auto“
Nothing(无结果)。
 LayoutInflater layoutInflater = (LayoutInflater) activity.getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);