执行以下操作:
在您的应用程序类中:
WXSDKEngine.registerComponent("yourImage", YourImage.class);
创建类YourImage.java,它应该是这样的:
public class YourImage extends WXComponent<ImageView> {
public YourImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
super(instance, dom, parent);
}
@Override
protected ImageView initComponentHostView(@NonNull Context context) {
ImageView imageView = new ImageView(context);
return imageView;
}
@WXComponentProp(name = Constants.Name.SRC)
public void setSrc(String src) {
if (src == null) {
return;
}
if(null != getHostView()) {
Picasso.with(WXEnvironment.getApplication()).load(src).into(getHostView());
}
}
}
在你的 vue/js 文件中
<yourImage class="image" :src="url"> </yourImage>
在您的 WeexUIFragment/Activity 中:通过 map 加载页面数据时,添加一个键和值,如下所示:
HashMap<String, Object> map = new HashMap<>();
map.add("image_url", "android local asset url")
map.put("PAGENAME", "");
mWXSDKInstance = new WXSDKInstance(YourCurrentActivity.this);
mWXSDKInstance.registerRenderListener(YourCurrentActivity.this);
mWXSDKInstance.render(pageName, weexJSUrl, map, null, WXRenderStrategy.APPEND_ASYNC);
在脚本/数据块中的 JS 文件中检索资产本地图像 url:
const url = _.get(weex,'config.image_url')
如果您需要更多帮助:您可以查看以下链接中的组件扩展部分:
https ://weex.incubator.apache.org/guide/extend-android.html