我正在尝试使用(Neil Davies实现)实现覆盖流。在我的应用程序中,我必须使用硬件加速,但是当我将硬件加速属性设置为true时,这个coverflow实现不能很好地工作(它使相机翻译非常不顺畅,并且在滚动时卡住)。
我尝试只在视图层禁用硬件加速-这对我没有帮助。
根据我在这里找到的一些解决方案,或者在这里(和其他一些),我必须在应用相机翻译后调用View.invalidate()
。正如您在附加的代码片段中看到的那样,我已经添加了这一行,但是在添加了invalidate()
调用之后,transformImageBitmap()
函数在一个永无止境的循环中被调用。正如我所理解的,在视图失效后,视图被"布局",transformImageBitmap()
再次被调用。这个永无止境的transformImageBitmap()
函数循环在我的应用程序中导致了一些前置问题。
下面是transformImageBitmap()函数:
private void transformImageBitmap(View child, Transformation t, int rotationAngle)
{
mCamera.save();
final Matrix imageMatrix = t.getMatrix();
final int imageHeight = child.getLayoutParams().height;
final int imageWidth = child.getLayoutParams().width;
mCamera.translate(0.0f, 0.0f, 100.0f);
float zoomAmount = 0;
zoomAmount = Math.abs((float) (rotationAngle));
mCamera.translate(0.0f, 0.0f, zoomAmount - 300.0f);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(imageWidth/2), -(imageHeight/2));
imageMatrix.postTranslate((imageWidth/2), (imageHeight/2));
mCamera.restore();
Log.e(LOG_TAG, "in transformImageBitmap");
child.invalidate();
}
我怎样才能使它正常工作?
我测试了一个解决方案并成功了。这是在你的活动中禁用硬加速。我的意思是整个活动,因为我也在视图上做了,bug仍然没有修复。
你所要做的就是添加:
<activity android:hardwareAccelerated="false" />
给你的活动清单