雖然四處尋找一種方法,以加快我的大文本陰影,我無意中發現了這個問題,答案是:
setShadowLayer Android API differences
使用:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
我大幅加快了我的應用程序中的所有文字陰影。
下面是我如何使用它的示例:
/**
* Set a backlight (shadow) on the passed TextView.
* @param textView
*/
void setBacklight(TextView textView) {
if (textView != null) {
float textSize = textView.getTextSize();
textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
textView.setShadowLayer(textSize,0,0,getColor(R.color.color_backlight));
}
}
根據這個文檔:
https://developer.android.com/guide/topics/graphics/hardware-accel.html
它說,你可以禁用的觀點硬件加速。
我不知道爲什麼,但不知怎的,這奇蹟般地加速了我的TextView陰影層。
我知道,我知道。該方法對於Canvas或Paint類不存在。所以要回答具體問題(所以我不會被每個人抨擊......),你可以在你打算繪製畫布的視圖上設置它。像這樣:
void inTheShadows(View view) {
float left = 0f;
float top = 0f;
float right = 10f;
float bottom = 10f;
Canvas canvas = new Canvas();
Paint paint = new Paint();
paint.setShadowLayer(8.f, 0, 0, 0xff000000);
canvas.drawRect(left, top, right, bottom, paint);
view.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
view.onDrawForeground(canvas);
}
如何繪製位圖並將其緩存?有時需要在運行時生成路徑/形狀... – Ixx 2017-07-09 13:21:48