在LayerDrawable与位图使用setLayerInset给人意想不到的效果 [英] Using setLayerInset on LayerDrawable with Bitmap gives unexpected results

查看:2355
本文介绍了在LayerDrawable与位图使用setLayerInset给人意想不到的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把动态小的点位图(热点)在使用LayerDrawable大量位图图像。索引为0的层中含有大量的图像。圆点图像上的位置被指定为我大的图像的百分比计算。例如,我可能有一个应该是从左边的50%和75%来自于大型基地图像的顶部的一个热点。为了在图像的正确部分的点位,我使用

I'm dynamically placing small dot bitmaps ('hotspots') over a large bitmap image using LayerDrawable. The layer at index 0 contains the large image. The dots' positions on the image are specified to me in terms of percentage of large image. For example, I might have a hotspot that is supposed to be 50% from the left and 75% from the top of the large base image. In order to position the dots over the correct part of the image, I'm using

setLayerInset(layer, leftOffset, topOffset, rightOffset, bottomOffset)

和计算基于包含LayerDrawable所述的ImageView的宽度和高度的偏移量。我很高兴的计算是正确的,合适的高度和宽度都被检索,并期望点,以显示正确,但事实并非如此。这些点正在沿Y轴倾斜和位置是不正确(太高,太靠左)。有没有人遇到过类似的问题,并找到了解决办法?

and calculating the offsets based on the width and height of the ImageView which contains the LayerDrawable. I'm happy that the calculations are correct and that the right height and width are being retrieved, and expect the dots to be correctly displayed, but they are not. The dots are being skewed along the Y axis and their positions are incorrect (too high and too far to the left). Has anyone encountered a similar problem and found a solution?

推荐答案

我花了一天半的时间这方面的工作,试图让数字感,这里是我发现了什么:

I spend a day and a half working on this, trying to make sense of the numbers, and here's what I found:

在我处理的情况,其中第一层包含BitmapDrawable和我设置的插图为subseqent层,在呼叫中的偏差:

In the situation I am dealing with, where the first layer contains a BitmapDrawable and I'm setting insets for the subseqent layers, the offset in the call:

setLayerInset(层,左偏移,topOffset,右偏移,bottomOffset)

setLayerInset(layer, leftOffset, topOffset, rightOffset, bottomOffset)

是<强>相对于所述位图中的第一层的尺寸,即使这些尺寸比在其被放置的DrawableLayer(视图越大例如,当位图正在由自动redimensioned视图)。

are relative to the dimensions of the bitmap in the first layer, even if those dimensions are greater than the view in which the DrawableLayer is being placed (e.g. when the Bitmap is being redimensioned automatically by the view).

离奇意外,但却是事实。希望这样可以节省别人一些时间。

Bizarre and unexpected, but true. Hope this saves somebody some time.

这篇关于在LayerDrawable与位图使用setLayerInset给人意想不到的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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