android中给定视图下视图的PorterDuff颜色效果
在安卓系统中,是否有可能设置一个视图,对其边界内可见的所有内容应用某种颜色过滤器?如本例所示:android中给定视图下视图的PorterDuff颜色效果,android,porter-duff,colorfilter,Android,Porter Duff,Colorfilter,在安卓系统中,是否有可能设置一个视图,对其边界内可见的所有内容应用某种颜色过滤器?如本例所示: 只是一个简单的矩形视图,可以反转它下面所有东西的颜色。当然,当用户滚动列表时,它也会反映在倒置的框中。是否有一些简单的方法可以使用滤色器、PorterDuff模式等进行操作?如果我可以简单地评论一下,我会的,因为我不确定我在这里是否正确。所以买家要当心,事情是这样的: 我认为你可以通过利用View.OnDragEve[]ntListener来达到这个效果。这是我的建议 我认为你应该调整android
只是一个简单的矩形视图,可以反转它下面所有东西的颜色。当然,当用户滚动列表时,它也会反映在倒置的框中。是否有一些简单的方法可以使用滤色器、PorterDuff模式等进行操作?如果我可以简单地评论一下,我会的,因为我不确定我在这里是否正确。所以买家要当心,事情是这样的: 我认为你可以通过利用View.OnDragEve[]ntListener来达到这个效果。这是我的建议 我认为你应该调整android中使用的拖放触发模式(即应用程序和操作系统之间的通信方式)。如何调整它将完全取决于应用程序中迫使一个视图进入另一个视图边界的机制。一旦你明白了这一点,你就可以通过以下方式实现高级色彩魔术: ,以及其他一些
对我来说,这听起来比另一种选择容易得多。祝你好运 您正试图使用如下视图层次结构解决此问题:
- 父视图
- 列表视图
问题是,在这个位置,
无法控制如何绘制inverserview
。但是您知道谁可以控制如何绘制ListView
<代码>列表视图的父布局没有。换句话说,您真正想要的是这样的层次结构:ListView
- 父级
- 逆变器布局
- 列表视图
现在,
负责绘制逆变器布局
,并可以对其应用效果列表视图
class InverterLayout extends FrameLayout { // structure to hold our color filter private Paint paint = new Paint(); // the color filter itself private ColorFilter cf; // the rectangle we want to invert private Rect inversion_rect = new Rect(100, 100, 300, 300); public InverterLayout(Context context) { super(context); // construct the inversion color matrix float[] mat = new float[] { -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255, 0, 0, 0, 1, 0 }; cf = new ColorMatrixColorFilter(new ColorMatrix(mat)); } @Override protected void dispatchDraw(Canvas c) { // create a temporary bitmap to draw the child views Bitmap b = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); Canvas cc = new Canvas(b); // draw them to that temporary bitmap super.dispatchDraw(cc); // copy the temporary bitmap to screen without the inversion filter paint.setColorFilter(null); c.drawBitmap(b, 0, 0, paint); // copy the inverted rectangle paint.setColorFilter(cf); c.drawBitmap(b, inversion_rect, inversion_rect, paint); } }
使用此选项时,确保您的子视图有自己的背景。如果视图是透明的,并且窗口背景显示为透明,则窗口背景不会反转,因为
无法控制窗口的绘制方式。以下是我要做的: 视图层次结构:InverterLayout
- 相对布局(或框架布局)
- 列表视图
- 客户视图
- 列表视图
我用这种方法实现了一个放大镜。它就像一个符咒。也许我可以稍后再发布一些代码,但我现在有点忙if (event.getAction() == MotionEvent.ACTION_MOVE) // Set Coordinates for the custom View. // Copy the bitmapCache of the ListView (jsut the portion you need // and send it to the customView. // Apply the filters you want. // Invalidate!
- 相对布局(或框架布局)
- 列表视图
现在,
- 逆变器布局
- 父级