有没有一种方法可以根据 xml 定义以编程方式创建 imageview 对象?

Is there a way to programatically create an imageview object based on xml definitions?

本质上,我希望在 XML 文件中定义 src、tint、layout:width、layout:height、alpha 等,然后基于 "new ImageView()"在 XML.

最简单的解决方案是创建一个布局资源来描述您的 ImageView,然后用 LayoutInflater 对其进行扩充。通常,尝试使用通过其 getLayoutInflater() 方法从 activity 或片段中获得的 LayoutInflater,以便按照您预期的方式应用样式和主题。

Android 中内置的任何其他东西都无法满足您的需求,尽管您当然可以实现自己的 "inflater of layouts",该 "inflater of layouts" 读取 XML 并创建相应的小部件。