Closed coderloveryan closed 5 years ago
我是这样加载本地资源图片的
//获取res/drawable目录下的图片Uri
public Uri getUriFromDrawableRes(Context context, int id) {
Resources resources = context.getResources();
String path = ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
+ resources.getResourcePackageName(id) + "/"
+ resources.getResourceTypeName(id) + "/"
+ resources.getResourceEntryName(id);
return Uri.parse(path);
}
style{
bgImgUrl:”getUriFromDrawableRes(R.drawable.image)“
}
mEngine.register(CardSupport.class, new CardSupport() {
@Override
public void onBindBackgroundView(View layoutView, Card card) {
if (layoutView instanceof ImageView && card != null) {
if (card.style != null && !TextUtils.isEmpty(card.style.bgImgUrl)) {
//设置tag是为了防止设置背景图循环触发布局
if (layoutView.getTag(R.id.home_recycler_view) == null || !layoutView.getTag(R.id.home_recycler_view).equals(card.style.bgImgUrl)) {
layoutView.setTag(R.id.home_recycler_view, card.style.bgImgUrl);
((ImageView) layoutView).setImageURI(Uri.parse(card.style.bgImgUrl));
}
}
}
}
@Override
public void onUnbindBackgroundView(View layoutView, Card card) {
if (layoutView != null) {
layoutView.setTag(R.id.home_recycler_view, null);
}
}
});
不能使用本地资源图片吗? 为什么我设置了“bgImgUrl”属性但是背景图没有展示,bgColor属性就可以用。卡片类型是container-fourColumn