alibaba / Tangram-Android

Tangram is a modular UI solution for building native page dynamically including Tangram for Android, Tangram for iOS and even backend CMS. This project provides the sdk on Android.
http://tangram.pingguohe.net/
MIT License
4.11k stars 526 forks source link

关于Card背景图问题 #172

Closed coderloveryan closed 5 years ago

coderloveryan commented 5 years ago

不能使用本地资源图片吗? 为什么我设置了“bgImgUrl”属性但是背景图没有展示,bgColor属性就可以用。卡片类型是container-fourColumn

whstywh commented 3 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);
                }
            }
        });