我正在使用svg-android库来处理应用程序中的SVG。长话短说,这个库从SVG生成一个(向量) PictureDrawable。
不幸的是,Android无法使用硬件加速将drawPicture()转换成画布,因此要实现加速,我必须将PictureDrawable内部的图片转换为位图。
问题是,如果在创建位图之后,可绘制主机的大小发生了变化,那么我必须重新调整到新的分辨率。
我已经超越了:
@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
if (Conf.LOG_ON) Log.d(TAG, "OnBoundsChange "+bounds);
createBitmapWithNewBounds();
}当我手动调用setBounds时,它可以工作,但是当可绘制的主机大小发生变化时,onBoundsChange()不会自动被调用(我也不知道是否应该调用)。
那么,是否有任何方法可以检测到它的主机大小发生了变化:
setBounds()的手动调用吗?onBoundsChange()?发布于 2016-02-10 18:33:18
您尝试过重写protected boolean onStateChanged(int[] state)吗?
我冒昧地将源代码和附带的文档包括在这里:/** * Override this in your subclass to change appearance if you recognize the * specified state. * * @return Returns true if the state change has caused the appearance of * the Drawable to change (that is, it needs to be drawn), else false * if it looks the same and there is no need to redraw it since its * last state. */ protected boolean onStateChange(int[] state) { return false; }
根据可绘制的源,默认实现是指示状态没有更改,正如您可以从返回值中看到的那样。因为可绘图不是扩展视图,这一定是他们要求一个layout()的模拟。因此,我认为如果简单地重写onStateChanged()以返回true,则应该会看到对onBoundsChanged()的调用。显然,天真的return true不是正确的解决方案,因为它依赖于传入的int[] state,但这应该会使您走上正确的轨道。
希望这能有所帮助。
https://stackoverflow.com/questions/22876096
复制相似问题