質問

I have this custom image format that BitmapFactory is unable to read. So I have written a derivate Resources class which decodes my image format into drawables. I return this custom Resources instance in Activity.getResources().

This solution works well for in-code resource reading, and I see images decoded like this.

But when I declare an image resource in layout files, all I get is a debug message in logcat saying

skia --- SkImageDecoder::Factory returned null

As if LayoutInflater doesn't even call activity.getResources()

役に立ちましたか?

解決

After much debugging it turns out that this is not possible to be done in this way.

TextView class constructor will call Resources.loadDrawable(TypedValue value, int id) which is private. loadDrawable only calls Resources.getCachedDrawable(LongSparseArray<WeakReference<ConstantState>> drawableCache, long key), which is again private.

How do Google's programmers achieve this kind of show-stoppers is beyond my comprehension. It takes extremely meticulous planning to give a programmer hope and then squash them later on with a well-aimed private, static or whatever. /rant

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top