Android的LayerDrawable.setDrawableByLayerId不工作的HTC感觉(和其他人?) [英] Android LayerDrawable.setDrawableByLayerId not working on HTC Sensation (and others?)

查看:949
本文介绍了Android的LayerDrawable.setDrawableByLayerId不工作的HTC感觉(和其他人?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LayerDrawable建立了一系列的底层图像(索引0)上的热点(1+索引)的。热点是基于用户界面交互增加,他们的位置是动态的,所以我在做这一切的编程方式而不是使用XML。作为进一步的(可能无关)的细节,我使用的是片段举行LayerDrawable,因为这是在FragmentStatePagerAdapter和ViewPager的上下文。

I am using LayerDrawable to build up a series of hotspots (indexes 1+) on an underlying image(index 0). The hotspots are added based on user interface interaction, and their position is dynamic, so I'm doing all of this programatically rather than using XML. As a further (probably irrelevant) detail, I am using a Fragment to hold the LayerDrawable, as this is in the contexts of an FragmentStatePagerAdapter and ViewPager.

问题是,当我试图通过所谓setDrawableByLayerId改变在LayerDrawable的绘制对象来更新图像时,图像不改变(尽管方法返回true,表示它找到层)。

The problem is that when I try to update an image by changing the Drawable in the LayerDrawable by called setDrawableByLayerId, the image does not change (despite the method returning true, indicating that it found the layer).

我怎样才能得到这个工作?

How can I get this to work?

推荐答案

在这里回答我的问题,希望这是给别人有用的在那里。我能得到这个在我的HTC感觉工作的唯一方法是从头开始重新创建LayerDrawable,再加上变化:

Answering my own question here, in the hope that it's useful to somebody out there. The only way I could get this to work on my HTC Sensation was by recreating the LayerDrawable from scratch, plus the change:

LayerDrawable oldLayerDrawable = (LayerDrawable) imageView.getDrawable();
Drawable[] layers = new Drawable[2];
layers[0] = oldLayerDrawable.getDrawable(0);
layers[1] = getResources().getDrawable(R.drawable.hotspot_dot);
LayerDrawable layerDrawable = new LayerDrawable(layers);
imageView.setImageDrawable(layerDrawable);

这不是pretty,但似乎这可能是一个已知的问题。

It's not pretty, but it seems that this might be a known problem.

这篇关于Android的LayerDrawable.setDrawableByLayerId不工作的HTC感觉(和其他人?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆