获取回收器视图中第一个不完全可见的元素不可见的像素量



我有一个带有元素的回收器视图,我需要获得第一个不完全可见的元素不可见的像素量,我该怎么做?

您可以从视图中获取像素,如下所示:

ImageView imageView = ((ImageView)v);
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);

现在,您可以通过以下方式获取每个频道:

int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);

颜色函数返回每个通道中的值。因此,您所要做的就是检查红色是否为 255,绿色和蓝色是否为 0,然后将 textView 文本设置为"它是红色"。请注意,说某物是红色的不仅仅是红色通道大于零。"当然,Cos 255-绿色和255-红色是黄色的。 您也可以将像素与不同的颜色进行比较。 例如:

if(pixel == Color.MAGENTA){
textView.setText("It is Magenta");
}

希望对您有所帮助。

好的,基本上在这种情况下,方法getLocalVisibleRect允许我想要
的:

Rect r = new Rect();
getChildAt(0).getLocalVisibleRect(r);
if (getChildAt(0).getWidth() >= r.right - r.left) { //Check if element is not fully visible, calculation of the invisible part.

最新更新